kaimallea / ismobile Goto Github PK
View Code? Open in Web Editor NEWA simple JS library that detects mobile devices.
License: MIT License
A simple JS library that detects mobile devices.
License: MIT License
Hi,
Thank you for this great library :).
After adding this library to my website, I got the below error
Uncaught TypeError: Cannot set property 'isMobile' of undefined
please advise
Thanks
Today, I'm using the current production version. When I'm testing on Chrome and changing phone to tablet, or phone to desktop, the plugin do not detect this changes.
This is just an improvement, but can be useful.
Can I use isMobile to distinguish android stock browser from chrome ? how ?
Hello,
This is my code:
var MOBILE_SITE = '/mobile/mobile.aspx', // site to redirect to
NO_REDIRECT = 'noredirect'; // cookie to prevent redirect
The redirect translates into:
..../mobile/index.html instead of ../mobile/mobile.aspx
Any thoughts?
tnx
frank
How about opting for the universal style of defining a module e.g.
(function isMobileModule(root, factory) {
// Define the UMD structure
})(window, (function isMobileInterface() {
// Define the module itself
}));
If you would like me to send a PR let me know.
isMobile.xxxxx
on v1.0.2 returns undefined
.
isMobile.any
isMobile.phone
isMobile.tablet
And isMobile.xxxxx.xxxxx
returns following error.
Uncaught TypeError: Cannot read property 'phone' of undefined
isMobile.apple.phone
isMobile.apple.ipod
isMobile.apple.tablet
isMobile.apple.device
(any mobile Apple device)isMobile.android.phone
isMobile.android.tablet
isMobile.android.device
(any mobile Android device; OkHttp user agents will match this)isMobile.amazon.phone
isMobile.amazon.tablet
isMobile.amazon.device
(any mobile Amazon Silk device)isMobile.windows.phone
isMobile.windows.tablet
isMobile.windows.device
(any mobile Windows device)isMobile.other.blackberry_10
isMobile.other.blackberry
isMobile.other.opera
(Opera Mini)isMobile.other.firefox
isMobile.other.chrome
isMobile.other.device
(any "Other" device)Related #94
we had a use case (have now fixed our side) where if you call
isMobile(undefined)
you get an error:
TypeError: Cannot read property 'use' of undefined
at module.exports (/Users/aUser/Projects/sanitycheck/node_modules/isMobile/lib/isMobile.js:2:13)
at Object.<anonymous> (/Users/aUser/Projects/sanitycheck/index.js:3:1)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3
Using ES6 import
is needed to run as a function to work.
Ex:
import React from 'react';
import isMobile from 'ismobilejs';
const Navbar = () => {
const navbarColllapseTarget = isMobile().phone ? '#nav-search-user' : '';
return (...);
}
export default Navbar;
This works: isMobile().phone
This does not: isMobile.phone
In documentation is specified to use isMobile
as an Object. In a previous project, I used as an Object.
Maybe I'm doing something wrong, I don't know.
Some time error occurs:
ReferenceError: navigator is not defined
at IsMobileClass (/node_modules/ismobilejs/isMobile.js:55:31)
I think because in node.js no 'navigator.userAgent' variable.
On iOS webview the useragent is not set.
Option to remedy this is to add a custom useragent setter inside ismobile. So that one can add own mobile user agents.
EDIT Probably not something that should be done. Closing issue after thoughts
master
branch failed. π¨I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.
You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. Iβm sure you can resolve this πͺ.
Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.
Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master
branch. You can also manually restart the failed CI job that runs semantic-release.
If you are not sure how to resolve this, here is some links that can help you:
If those donβt help, or if this issue is reporting something you think isnβt right, you can always ask the humans behind semantic-release.
The npm token configured in the NPM_TOKEN
environment variable must be a valid token allowing to publish to the registry https://registry.npmjs.org/
.
If you are using Two-Factor Authentication, make configure the auth-only
level is supported. semantic-release cannot publish with the default auth-and-writes
level.
Please make sure to set the NPM_TOKEN
environment variable in your CI with the exact value of the npm token.
Good luck with your project β¨
Your semantic-release bot π¦π
Hi,
Would you be interested in a PR that adds explicit support for Amazon devices?
I would use this page as a reference.
Hi @kaimallea I'm using this lib, it's awesome.
Is there any plan to rewrite it using ES6 features, and then browserify to generate an dist file?
[]s
Facebook Ipad app has an integrated browser, which user agent contains a lot of things:
Mozilla/5.0 (iPad; CPU OS 8_1 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12B410 [FBAN/FBIOS;FBAV/20.1.0.15.10;FBBV/5758778;FBDV/iPad5,4;FBMD/iPad;FBSN/iPhone OS;FBSV/8.1;FBSS/2; FBCR/;FBID/tablet;FBLC/fi_FI;FBOP/1]
Regexp for Phone detection catches "iPhone OS" -> incorrect detection
The easiest fix is propably to remove anything after [FBAN, like this:
var ua = userAgent || navigator.userAgent;
var tmp = ua.split("[FBAN");
if (typeof tmp[1] != "undefined") { ua = tmp[0]; }
This phone detected like not phone.
Is there any way I could include symbian support in your library? Your library is great by itself for modern times, but my company requires support for symbian, megoo and other stuff that's probabbly not in production anymore. π
The npm package doesn't have the same name as the AMD module (ismobilejs versus isMobile).
So when you use webpack, you have to create an alias.
I think it should be fine if you don't give a name to your AMD module (l132) :
define([], global.isMobile = instantiate());
instead of
define('isMobile', [], global.isMobile = instantiate());
not support UC on iphone ..
Windows Phone 10 is not correctly detected by this plugin.
isMobile.windows.device
returns false
Mobile device model: Nokia Lumia 550
Operating system: Windows 10 Mobile
Browser: Microsoft Edge 38.14393.67.0
I'm testing with Windows Phone Lumia and this isn't working. It keeps showing apple phone.
ESLint generates an error for the other_firefox
RegExp pattern:
Error 19,24: Unnecessary escape character: \M. (no-useless-escape)
The fix is to remove the unnecessary backslash in front of the M here.
- other_firefox = /\Mobile(?:.+)Firefox\b/i; // Match 'Mobile' AND 'Firefox'
+ other_firefox = /Mobile(?:.+)Firefox\b/i; // Match 'Mobile' AND 'Firefox'
I've created a PR to fix this issue.
I'm not sure this is an issue or just my wrong.
At first, I include isMobile.js
in my AMD project use the following code, it worked very well.
require( [ "app", "isMobile" ], function(App, isMobile) {
//...
});
But when I use r.js
to optimize and combine my project and run again, the following error has occurred.
Mismatched anonymous define() module: [object Object]
Then I found the description of this error form the page of requirejs .
So I think the problem may be in the line #105~106 of isMobile.js
:
//AMD
define(global.isMobile = instantiate());
I tried to modify the code to look like this:
//AMD
define( 'isMobile', [], global.isMobile = instantiate() );
Then it worked fine.
So I just submit this issue, and I'm not a veteran of the requirejs, anyone could give me some advice on this?
Btw, very nice project :).
Thank you for your project,I tested a lot, It's "false" use "isMobile.android.phone" or "isMobile.phone" in chrome for android.thank you!
the latest version on NPM is 0.4.0
What you think to rewrite the library using CoffeeScript? We could start by Jasmine code.
Let me know what you think about this idea.
Brilliant utility!
Any chance on it being available via Bower? π
I have laptop with a touch display. When the script executes it thinks it is a mobile browser.
Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; Touch; MAGWJS; rv:11.0) like Gecko
To fix I removed the word touch from regular expression. I am unsure what this might of excluded for real mobile devices.
v0.5.1 does call window reference and handles it if it doesn't exist.
in v^1.xx.xx it calls window which doesn't allow ssr.
For those wondering any ANT DESIGN users who use the latest version (^3.23.1) ismobilejs is used by some packages and has updated to ismobilejs v1.xx.xx.
In your package.json in resolutions place ismobilejs as 0.5.1 for ssr
Hi Kai,
We ran into error as 'split not a function' in iOS 9.3.2 Safari. In javascript, navigator.userAgent returns false as a boolean value, which doens't have 'split' function while it was called later. Temporarily we changed code in version 0.4.1 as below from:
var ua = userAgent || navigator.userAgent
to:
var ua = userAgent || navigator.userAgent || '';
Just let you know.
Thanks
Li
The latest tag and release is 0.3.2, so with bower we can only install that version back from 2014-04-02
Please fix this, so we can use your package with bower!
Details:
$ bower install isMobile#0.3.4 --save
bower not-cached git://github.com/kaimallea/isMobile.git#0.3.4
bower resolve git://github.com/kaimallea/isMobile.git#0.3.4
bower ENORESTARGET No tag found that was able to satisfy 0.3.4
Additional error details:
Available versions: 0.3.2, 0.3.1, 0.3.0
Hey! I am assuming this is under the MIT license, but for sake use in projects you should include and official license file!
There are multiple regular expression used for parsing the user agent which are vulnerable to ReDoS, e.g.:
/(?=.*\bAndroid\b)(?=.*\bSD4930UR\b)/i
The slowdown is relatively serious because multiple such regexs are checked against the user agent: for 40.000 characters around 22 seconds matching time. I would suggest one of the following:
If needed, I can provide an actual example showing the slowdown.
Desktop User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393
Phone User-Agent: Mozilla/5.0 (Windows Phone 10.0; Android 4.2.1; Microsoft; Lumia 650) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Mobile Safari/537.36 Edge/14.14263
Can you add AMD support?
when trying to run ismobile as an npm module in nodejs there is an error returned:
ReferenceError: navigator is not defined
at IsMobileClass (/Users/aUser/Projects/sanitycheck/node_modules/ismobilejs/isMobile.js:58:31)
at Object.<anonymous> (/Users/aUser/Projects/sanitycheck/index.js:3:1)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3
Nexus 9 is not being detected as a tablet.
You should add resolution detection for redirect. My android tablet is showing up as mobile but it is a HD screen. Anything with a resolution above 1280 x 800 should show as a tablet.
The Nokia Lumia 930 device is recognized as apple device when checking "isMobile.apple.device"
Hi, I noticed that for some reason, including the minified version on the head it causes a 500 internal server error. Includin version NON minified works great.
Per #96, clarify the usage with better examples for the most common use cases.
isMobile
object with resultsI used to write if(isMobile.any){...}, but somehow it doesn't work anymore, I have to do if(isMobile.any()){...} instead to make it work.
but there is one thing that is more wierder, all my old projects that running on the server are all fine with if(isMobile.any){...}
can you help me with this issue. thank you so much.
Please read this comment.
http://stackoverflow.com/a/9039885/1925391
In Chrome Inspector the Galaxy Tab shows as phone, don't have a real Galaxy Tab so I can't confirm whether it's just the inspector.
With this agent:
Mozilla/5.0 (Android; Mobile; rv:27.0) Gecko/27.0 Firefox/27.0
I get javascript error:
No match with webkitVersion
ua.match(webkitVersion)
Hi author; could you please add an open source license to the NPM package?
Hello,
After upgrading ismobilejs
version from v0.5.2
, which is present on NPM but not in github releases btw, to v1.0.1
the result of webpacks import function is {}
.
Executed in mounted
hook of js framework, used in browser, built with webpack.
const { default: isMobile } = await import('ismobilejs');
console.log(isMobile); //> {}
Thank you in advance!
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.