rguerreiro / express-device Goto Github PK
View Code? Open in Web Editor NEWDevice detection library for node.js based on the user-agent, built on top of express
Home Page: http://rguerreiro.github.io/express-device/
License: MIT License
Device detection library for node.js based on the user-agent, built on top of express
Home Page: http://rguerreiro.github.io/express-device/
License: MIT License
it didn't work
Hey there
I've been using express for quite some time and recently switched to typescript.
The express-device package was always a must have for all my applications but now, i am missing the lack of typescript support.
Are there plans to create such support?
Thanks in advance.
Greetings
Most vendors that support HbbTV will add the case-insensitive 'hbbtv' into the user-agent.
http://www.webapps-online.com/online-tools/user-agent-strings/dv/plugin502101/hbbtv
Would you support this and translate it to 'tv'
Thanks for your useful library, however there is one small issue: wget seems to be interpreted as a 'phone,' and I think it should be a 'bot.' Here is what I get when wgetting a simple page which simply res.sends the req.device:
{"parser":{"options":{"emptyUserAgentDeviceType":"desktop","unknownUserAgentDeviceType":"phone","botUserAgentDeviceType":"bot","carUserAgentDeviceType":"car","parseUserAgent":true},"useragent":{"family":"Wget","major":"1","minor":"16","patch":"3","device":{"family":"Other","major":"0","minor":"0","patch":"0"},"os":{"family":"Other","major":"0","minor":"0","patch":"0"}}},"type":"phone","name":"Other"}
If I perform the same experiment using curl, then it correctly returns as a bot.
This was tested using: [email protected] [email protected] and [email protected]
One that is on the pipeline for a very long time is parsing the OS. But that is already done in the ua-parser package. Is it really necessary on the express-device?
What other ideas do you have that make sense on adding to express-device?
I'm seeing the following user agents being detected as "phone":
Mozilla/5.0 (iPhone; CPU iPhone OS 8_3 like Mac OS X) AppleWebKit/537.36 (KHTML, like Gecko) Version/8.0 Mobile/12F70 Safari/600.1.4 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)
Mozilla/5.0 (iPhone; CPU iPhone OS 83 like Mac OS X) AppleWebKit/600.1.4 (KHTML like Gecko) Version/8.0 Mobile/12F70 Safari/600.1.4 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)
More complete list here:
https://support.google.com/webmasters/answer/1061943?hl=en
Seems to me they should be categorized as "bot" to be consistent with the fact bot-ness trumps device type for desktop. What do you think?
After updating express to v3.4.8 started to receive following error
TypeError: Object function app(req, res, next){ app.handle(req, res, next); } has no method 'enableDeviceHelpers'
In the docs you list that emptyUserAgentDeviceType
defaults to phone and unknownUserAgentDeviceType
defaults to desktop but looking at your code I see the opposite.
Not sure if you're ever going to work on this code again, but in case someone else wants to use it and gets into the same issue I had
I make a simple patch in my node / express project
if(req.device.type != 'phone' || req.headers['user-agent'].indexOf('facebookexternalhit') !== -1) {
lang.page = '/';
res.render('index',lang);
} else {
lang.page = '/';
res.render('mobile/index',lang);
}
nevermind, was my fault
Google has different bots for phone and desktop: see https://support.google.com/webmasters/answer/1061943?hl=en .
It'd be nice to be able to tell both whether it's a bot and which form-factor it's crawling for.
maybe windows azure and some hosting services not support npm install using git...
dependent public npm repogitory. it's better support some cloud platforms.
i attach windows azure error log.
thank you. your module. it's very good. ๐
npm http GET http://registry.npmjs.org/express-device
npm http GET http://registry.npmjs.org/coffee-script
npm http 200 http://registry.npmjs.org/coffee-script
npm http GET http://registry.npmjs.org/coffee-script/-/coffee-script-1.6.1.tgz
npm http 200 http://registry.npmjs.org/express-device
npm http GET http://registry.npmjs.org/express-device/-/express-device-0.3.5.tgz
npm http 200 http://registry.npmjs.org/coffee-script/-/coffee-script-1.6.1.tgz
npm http 200 http://registry.npmjs.org/express-device/-/express-device-0.3.5.tgz
npm ERR! git clone git://github.com/publicclass/express-partials.git CreateProcessW: The system cannot find the file specified.
npm ERR! Error: `git "clone" "git://github.com/publicclass/express-partials.git" "C:\\DWASFiles\\Sites\\ssen\\Temp\\npm-13516\\1362820148766-0.6230687508359551"` failed with 127
npm ERR! at ChildProcess.<anonymous> (D:\Program Files (x86)\nodejs\node_modules\npm\lib\utils\exec.js:56:20)
npm ERR! at ChildProcess.emit (events.js:70:17)
npm ERR! at maybeExit (child_process.js:358:16)
npm ERR! at Socket.<anonymous> (child_process.js:463:7)
npm ERR! at Socket.emit (events.js:67:17)
npm ERR! at Array.<anonymous> (net.js:335:10)
npm ERR! at EventEmitter._tickCallback (node.js:190:38)
npm ERR! [Error: `git "clone" "git://github.com/publicclass/express-partials.git" "C:\\DWASFiles\\Sites\\ssen\\Temp\\npm-13516\\1362820148766-0.6230687508359551"` failed with 127]
npm ERR! You may report this log at:
npm ERR! <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR! <[email protected]>
npm ERR! System Windows_NT 6.1.7601
npm ERR! command "D:\\Program Files (x86)\\nodejs\\\\node.exe" "D:\\Program Files (x86)\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "--production"
npm ERR! cwd C:\DWASFiles\Sites\ssen\VirtualDirectory0\site\wwwroot
npm ERR! node -v v0.6.20
npm ERR! npm -v 1.1.37
npm ERR! message `git "clone" "git://github.com/publicclass/express-partials.git" "C:\\DWASFiles\\Sites\\ssen\\Temp\\npm-13516\\1362820148766-0.6230687508359551"` failed with 127
npmSetConsoleTitleW: The operation completed successfully.
...and let developers decide how they want to handle it.
This line:
Example: iPhone. If the option parseUserAgent is set to false, then it will return an empty string
Makes it seem like the default is true. At least to me. Totally your call. I'd suggest:
Example: iPhone. parseUserAgent is set to false by default and will return an empty string.
This is more likely my goof up but I keep getting the message "device not defined".
I ran npm install express-device
the added this line to my server.js
app.use(device.capture());
I am also using express 3.
Device type is returned as desktop in Safari, user agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.1 Safari/605.1.15
But correctly as tablet in Chrome on the same device, user agent:
Mozilla/5.0 (iPad; CPU OS 14_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/91.0.4472.80 Mobile/15E148 Safari/604.1
There's something weird going on with the publish history of this module. I cleaned my npm cache to make sure the issue wasn't on my end. When I install this module I get a package.json with the correct latest version 0.3.9 but it has a completely different JSON that includes the readme string. https://gist.github.com/esco/036ed9e2e374fa268e3b
The package.json in the master branch is fine because it doesn't have the "readme" field and when I download the tgz direclty it doesn't have it either.
Both package.json files have "version": "0.3.9".
The problem with this is that when express-device is required, the contents of ReadME.md are stored in require.cache which is a waste of memory.
Is anyone able to replicate this?
The code:
ua.match(/iP(a|ro)d/i)
detect IPad, IProd?
This way express-device can be used out-of-box with sails.js or other similar frameworks
I'm really keen to use this module's functionality, but I only really need the code from https://github.com/rguerreiro/express-device/blob/master/lib/device.js#L48-L106 that maps UA strings to device types.
It'd be really useful if that mapping was separated out into its own module, which this one can then depend on, so the mapping can be used standalone without need for the (unnecessary in my case) coupling to express.
Mozilla/5.0 (X11; u; Linux; C) AppleWebKit /533.3 (Khtml, like Gheko) QtCarBrowser Safari /533.3
Hello, I have tried running the example application, and when I do, the following error stack is produced:
app.enableDeviceHelpers();
^
TypeError: Object function app(req, res, next){ app.handle(req, res, next); } has no method 'enableDeviceHelpers'
at Function.<anonymous> (/Users/ajay/Sites/pipeline/carbon/node/test.js:17:9)
at Function.app.configure (/Users/ajay/Sites/pipeline/node_modules/express/lib/application.js:395:61)
at Object.<anonymous> (/Users/ajay/Sites/pipeline/carbon/node/test.js:7:5)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.runMain (module.js:492:10)
at process.startup.processNextTick.process._tickCallback (node.js:245:9)
It seems the two functions are not binding to express.application properly. I am using express 3.1.1.
Here's a list of UAs which were marked as bots. They are from registrations on my site.
https://gist.github.com/kongelaks/7a6634f2fa96e1cf30be
They match the UA patterns found here: http://docs.aws.amazon.com/silk/latest/developerguide/user-agent.html
(ua.match(/Kindle/i) || (ua.match(/Mac OS/i) && ua.match(/Silk/i)) || (ua.match(/AppleWebKit/i) && ua.match(/Silk/i)))
I posted my error code below. This occurred from a ubuntu instance on ec2. You guy probably just need to update the registry.
npm http GET https://registry.npmjs.org/express-device npm http 304 https://registry.npmjs.org/express-device npm WARN
git config --get remote.origin.urlreturned wrong result (git://github.com/publicclass/express-partials.git) execvp(): No such file or directory npm ERR! git clone git://github.com/publicclass/express-partials.git execvp(): No such file or directory npm ERR! Error:
git "clone" "--mirror" "git://github.com/publicclass/express-partials.git" "/home/ubuntu/.npm/_git-remotes/git-github-com-publicclass-express-partials-git-4988eaf2" failed with 127
When a unknown user-agent requests a ressource, it gets detected as mobile. When no user-agent is set at all, it gets detected as desktop. That's not very consistent in my opinion.
The default device.type should be set to 'desktop' (makes it consistent with no user-agent set). Alternatively, we could expose an option to let us set the default device.type on initialization.
Every time request is made with postman, it detects device type as phone
.
It shouldn't be phone
, bot
can be better choice but not sure.
req.device.type
on ipad pro 12.9 inch returns phone
Tested on xcode emulator only, cannot guarantee same result on real device. Can anyone confirm?
$ yarn add express-device
yarn add v1.9.4
[1/4] Resolving packages...
[2/4] Fetching packages...
[-----------------------------------------------------------------------------------------------------------------] 0/881(node:18575) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
info [email protected]: The platform "linux" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
success Saved 4 new dependencies.
info Direct dependencies
โโ [email protected]
info All dependencies
โโ [email protected]
โโ [email protected]
โโ [email protected]
โโ [email protected]
Done in 60.49s.
Hi, I am trying to use this library to support SSR (reference: mui/material-ui#6068 (comment)). I got the warning above, thought sharing with you.
Search for CrKey in the user-agent string
Done
can someone please add an example of how this works in Express itself
app.use(device.capture());
app.use(function(req,res,next){
device.is_desktop /// no indication that this is valid, please include example
device.is_mobile /// no indication that this is valid, please include example to keep us from guessing
});
How to use it with native Node.js with res.write and create server only (without Express and ejs)?
example:
const device = require('express-device')
http.createServer(function(req, res) {
res.writeHead('blablabla')
if (is_desktop) {
res.write('hi desktop)
}
res.end()
}
thanks 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.