hgoebl / mobile-detect.js Goto Github PK
View Code? Open in Web Editor NEWDevice detection (phone, tablet, desktop, mobile grade, os, versions)
Home Page: http://hgoebl.github.io/mobile-detect.js/
License: MIT License
Device detection (phone, tablet, desktop, mobile grade, os, versions)
Home Page: http://hgoebl.github.io/mobile-detect.js/
License: MIT License
The os() function is a bit broken... It simply cycles through the oss rules, and returns the key of the first matching rule. If it's going to do this, the rules should be carefully re-ordered. For example, this is the user agent for Windows Phone 8.1:
Mozilla/5.0 (Mobile; Windows Phone 8.1; Android 4.0; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; Microsoft; Virtual) like iPhone OS 7_0_3 Mac OS X AppleWebKit/537 (KHTML, like Gecko) Mobile Safari/537
It contains the string "Android" so it matches the first "Android" rule. Here's some explanation from Microsoft: http://blogs.msdn.com/b/ie/archive/2014/07/31/the-mobile-web-should-just-work-for-everyone.aspx
Even if it didn't contain "Android", it would match the "Windows Phone [0-9.]+" part of WindowsMobileOS. This isn't ideal - I assume we should be returning WindowsPhoneOS.
I wasn't sure whether to post this here or in the Mobile_Detect library... The os() function doesn't exist in the PHP library, and perhaps this is the reason...
I think the version number in the version dated 2015-12-28 has to be 1.3.1, but in the file "mobile-detect.min.js" the version is "mobile-detect - v1.3.0 - 2015-12-28".
I tried using this library as part of a UDF script in Google BigQuery and got the "Error: unknown environment" log message at like 990 (mobile-detect.js) and saw that the comment on the line above said that I should file a bug report when I got that error.
How can I help fix this issue?
Hello
Thanks for you library
I noticed that Windows 10 OS and edge are not detect by version 1.3.1
Specifically, the presence of "Goanna/xx" in the UA in v26+ is detected as a Wiko Goa phone.
Some more user agents:
Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729; rv:11.0) like Gecko
Mozilla/5.0 (MSIE 10.0; Windows NT 6.1; Trident/5.0)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36
If attempting to use destructuring when creating constructor like this:
const { os, userAgent } = new MobileDetect(window.navigator.userAgent);
The following error is thrown:
It seems to be due to this
being undefined when checking for the cache. A small check for the existence of this
should fix the problem, but then I think it will no longer use the cache.
Will attempt a PR sometime soon.
I found an issue regarding to determining device based on screen width.
We divide screen width on device pixel ratio.
var physicalPixelWidth = window.screen.width,
pixelRatio = window.devicePixelRatio || 1,
cssPixelWidth = physicalPixelWidth / pixelRatio;
It's mistakenly because window.screen.width already has density independent pixels value (tested on several real devices).
So I suggest to eliminate this division.
Actually it'll be good to use smallest-width qualifier approach instead - the same as android use to determine small/large screen devices.
Do you plan to generate a new build based on new the version of Mobile-detect.php which is 2.8.4?
Precondition:
Have use agent considered as Mobile but not Tablet, for instance Acer nr11:
"Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; Acer; Allegro)"
Actual:
Both tablet() and phone() methods return positive value ("UnknownMobile").
Expected:
I suppose that calling tablet() or phone() in this case should return falsy value (null). Because generally table/phone checking are implemented like so:
if (md.tablet()) {}
//or
if (md.phone()) {}
but not like
if (md.tablet() && md.tablet() !== "UnknownMobile") {}
My "Samsung S2 (GT-I9100) is detected as "UnknownPhone" under "Opera Mini 7.6.40234" and "Opera Mini (New) 8.0.1807.91281". It seems that mobile-detect.js cannot identify the userAgent.
The fallback to the regex of detectmobilebrowsers.com seems to work, because it throws "UnknownPhone". Now I use the following working code:
var md = new MobileDetect(window.navigator.userAgent);
if (md.mobile() || md.mobile()=="UnknownPhone" || md.mobile()=="UnknownMobile" || md.mobile()=="UnknownTablet") {
// If a mobile or an unknown device (mobile, tablet, mobile) with not more than 600px is detected, switch to mobile site version
location.href = "https://m.xyz.com/";
For the moment, I don't succeed to make it work with browserify.
var MobileDetect = require('mobile-detect')
var md = new MobileDetect( window.navigator.userAgent )
console.log( md.mobile() ) // null
console.log( md.phone() ) // null
console.log( md.tablet() ) // null
console.log( md.userAgent() ) // null
console.log( md.os() ) // null
console.log( md.is('iPhone') ) // false
console.log( md.is('bot') ) // false
console.log( md.version('Webkit') ) // NaN
console.log( md.versionStr('Build') ) // null
console.log( md.match('playstation|xbox') ) // false
console.log( md ) // Object { ua: "Mozilla/5.0 (Macintosh; Intel Mac O…", _cache: Object, maxPhoneWidth: 600 }
With recent changes:
Thanks for sharing this util project.
I have a problem, Asus MemoPad FHD 10 Tablet is not recognized neither mobile device or tablet or phone.
Could you tell me if I have to do something to make it works?
Thanks' in advance
R.
As the docs on Facebook state they are using 'Facebot' name for their crawler.
In version 0.4.3, this user-agent:
Mozilla/5.0 (Linux; Android 5.0.2; SM-G9250 Build/LRX22G; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/43.0.2357.121 Mobile Safari/537.36 [FB_IAB/FB4A;FBAV/35.0.0.48.273;]
Will give 'UnknownMobile'
with the .phone()
method call.
In version 1.2.0 the same method returns null
.
Sometimes we get the following error:
TypeError: Cannot call method 'substr' of undefined
at isMobileFallback (/var/www/ourproject/node_modules/mobile-detect/mobile-detect.js:338:62)
at prepareDetectionCache (/var/www/ourproject/node_modules/mobile-detect/mobile-detect.js:362:13)
at MobileDetect.mobile (/var/www/ourproject/node_modules/mobile-detect/mobile-detect.js:433:13)
Why when using with desktop, these functions give blank result:
userAgent()
os()
And is this possible to do something like md.is('Desktop')?
How I can build mobile-detect without php and this files?:
path.join(__dirname, '..', '..', 'Mobile-Detect', 'tests', 'ualist.json')
Why you don't using just grunt (or gulp), without generate script?
var MobileDetect = require('mobile-detect');
var ua='Mozilla/5.0 (Linux; U; Android 4.1.2; en-us; SPH-L710 Build/JZO54K) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30';
var md = new MobileDetect(ua);
console.log(md.mobile());
Result is: NULL
cant detect android 5 and anroid 6 versions
The UA is:
Mozilla/5.0 (Linux; Android 4.4.2; en-us; SAMSUNG SM-T530NU Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Version/1.5 Chrome/28.0.1500.94 Safari/537.36
Since the check for a phone is before that for a tablet, its being identified as a phone - mobielDetectRules for a phone contain the regex /Samsung/i. This causes the regex for a Samsung tablet /SAMSUNG.*Tablet/ to never be matched since the check for a phone is made before that for a tablet. Should the checking order be reversed (tablet, then phone)?
ua
'Mozilla/5.0 (Linux; Android 4.4.4; SM-N910C Build/KTU84P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.85 Mobile Safari/537.36'
Example UAs: https://developer.mozilla.org/en-US/docs/Web/HTTP/Gecko_user_agent_string_reference#Firefox_OS
Mobile: Mozilla/5.0 (Mobile; rv:26.0) Gecko/26.0 Firefox/26.0
Tablet: Mozilla/5.0 (Tablet; rv:26.0) Gecko/26.0 Firefox/26.0
It reports tablet()
being UnknownTablet
for the mobile UA.
Hello,
the following two user agent strings are both not detected by library (first one seems to be a web view from android)
Thank you
Testing in browserstack I got this results:
Not sure if this is intended but this library think the S5 is a tablet... and a phone.
This is the current user agent -
'Mozilla/5.0 (Linux; Android 6.0.1; SM-G930F Build/MMB29K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.85 Mobile Safari/537.36'
Hi! Thanks for this great lib. Is it possible to add to the phone list Huawei, Meizu and Xiaomi? These brands become more and more popular. FYI, during my tests on Huawei Honor 3C H30-U10 I had been receiving next values from methods:
Hi,
today i've run into trouble detecting Praktica tablet (TP750 3GGSM) as unknown tablet - or generally speaking as a mobile device - in Google Chrome (v39.0.2171.93) on Android 4.0.4.
User agent string reported by Chrome:
Mozilla/5.0 (Linux; Android 4.0.4; TP750 3GGSM Build/IMM76I) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.93 Safari/537.36
After investigating for a while I've figured out that the problem is in detectMobileBrowsers.fullPattern regular expression. According to documentation at https://developer.chrome.com/multidevice/user-agent UA string on Android contains Mobile keyword only for phones and not for tablets.
Possible solution would be to modify regular expression from:
/(android|bb\d+|meego).+mobile|...
to
/(android|bb\d+|meego).+(mobile)?|...
if it does not any have side effects.
Currently comes back as desktop. UA is
Mozilla/5.0 (Linux; Android 4.4.2; LG-V510 Build/KOT49H.L004) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.141 Safari/537.36
Suggested mod:
"LGTablet": "\\bL-06C|LG-V\\d+|LG-VK\\d+\\b",
Hi!, great script, but it doesn't work OK with Windows Phone.. I've uploaded an screencapture taken with my Windows Phone - Lumia 1020 running IE 11, OS version 8.1
As you can see, it says os is Android, mobile() returns iPhone, and also is('iPhone') and is('AndroidOS') returns true
It would be wonderful if you can fix this problem and let me now then
Thanks in advance for all your effort
In order to import the constructor in Typescript with the new typings you need have the following:
import {MobileDetect} from "mobile-detect";
But the source suggests that you need to import it using:
import * as MobileDetect from "mobile-detect";
or
import MobileDetect = require("mobile-detect");
My Lenovo TAB 2 is detected as desktop. My device name in User Agent is "Lenovo TAB 2 A10-70L"
This is not an issue but a feature proposal - it would be much appreciated to get extra category for phablets, which are currently detected as phones.
Thank you for updating the integration of detection logic to [email protected]
I just have a short question. Do you use the current Version "Detect Mobile Browsers" (http://detectmobilebrowsers.com/) for integration which was released at 1 August 2014?
Not builded if connect through webpack require (). Need changed this code
((function (undefined) {
if (typeof define === 'function' && define.amd) {
return define;
} else if (typeof module !== 'undefined' && module.exports) {
return function (factory) { module.exports = factory(); };
} else if (typeof window !== 'undefined') {
return function (factory) { window.MobileDetect = factory(); };
} else {
// please file a bug if you get this error!
throw new Error('unknown environment');
}
})());
on this
((function (undefined) {
if (typeof module !== 'undefined' && module.exports) {
return function (factory) { module.exports = factory(); };
}
else if (typeof define === 'function' && define.amd) {
return define;
} else if (typeof window !== 'undefined') {
return function (factory) { window.MobileDetect = factory(); };
} else {
// please file a bug if you get this error!
throw new Error('unknown environment');
}
})());
The README has a clear warning about the reliability of this kind of detection, ok. But if all I need is just check for mobile (smartphone and tablets), would it still have this reliability issue?
Please can you integrate the detection logic from [email protected] ?
https://github.com/serbanghita/Mobile-Detect/releases
Support AMD for using it with RequireJS?
UPD: See for pull request: #8
Testing against this user agent:
SAMSUNG-SGH-E250/1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 UP.Browser/6.2.3.3.c.1.101 (GUI) MMP/2.0 (compatible; Googlebot-Mobile/2.1; +http://www.google.com/bot.html)
is('MobileBot') returns false, seems like the check for utils.bot should come after utils.MobileBot on lines 262 and 263, since the regex for 'Google-Mobile' won't get a chance to fire since the regex for 'GoogleBot' will return true first.
From this list of mobile bots https://developers.google.com/webmasters/mobile-sites/references/googlebot?hl=en, I believe this might fix the last 2.
The first one:
Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)
will probably still return true only for a 'Bot'.
Thanks,
Darren
Example (Xiaomi Redmi Note 3 PRO, Android 5.1.1): Mozilla/5.0 (Linux; Android 5.1.1; Redmi Note 3 Build/LMY47V) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Mobile Safari/537.36
Example (Asus ZenFone Max, Android 6.0.1): Mozilla/5.0 (Linux; Android 6.0.1; ASUS_Z010D Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Mobile Safari/537.36
And maybe lots of others. I think, this is critical, these phones are not new. The latest version of library is used.
Related: #54
user agent
'Mozilla/5.0 (Linux; Android 5.0.2; SM-G920F Build/LRX22G) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.85 Mobile Safari/537.36'
Can't recognize LG G3 different devices.
I encountered the issue on the LG G3 D855 but I can also see that there are devices of types:
D850 D851 D724 D690
I found the following link http://www.webapps-online.com/online-tools/user-agent-strings/dv/brand574739/lg-g3
For the LG G4 I read somewhere that it supposed to be H810 but again I didn't investigate it thoroughly.
Hi, great thanks to this nice module!
I found a problem in detecting iOS version today.
var md = new MobileDetect( window.navigator.userAgent );
console.log( window.navigator.userAgent );
console.log( md.version('iOS') );
This code gets these results.
Mozilla/5.0 (iPhone; CPU iPhone OS 10_1_1 like Mac OS X) AppleWebKit/602.2.14 (KHTML, like Gecko) Version/10.0 Mobile/14B100 Safari/602.1
10.11
My iPhone is iOS 10.1.1
but, response is 10.11
.
Would you like to fix this?
The Motorola G 2nd generation is detected as tablet, but it is a phone. Could you add it to the phones list?
User agent is:
Mozilla/5.0 (Linux; Android 5.0.2; XT1068 Build/LXB22.46-28.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.94 Mobile Safari/537.36
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.