navigator is not defined (node.js)
Closed this issue · 3 comments
exentrich commented
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.
palamccc commented
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);
kaimallea commented
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.
torvalde commented
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