kaimallea/isMobile

navigator is not defined (node.js)

Closed this issue · 3 comments

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.

Check the last paragraph in readme.md, you have to pass useragent to isMobile

var isMobile = require('ismobilejs');
console.log(isMobile(req.headers['user-agent']).any);

Hi @exentrich ,

@palamccc is correct (thanks) -- in a browserless environment, such as node.js, there is no navigator object, so you need to manually pass in a user agent string, as isMobile assumes a browser context by default as it depends on user agents for detection.

I believe this is a bug, isMobile should accept an empty string without failing....

a workaround is to write:

isMobile(req.headers['user-agent'] || "unknown").any