rguerreiro / device Goto Github PK
View Code? Open in Web Editor NEWDevice type detection library based on the useragent string. Refactored from my express-device repo.
License: MIT License
Device type detection library based on the useragent string. Refactored from my express-device repo.
License: MIT License
Here's an iPhone 10 user agent string which is not recognized as "phone"
by the library (falling back to the unknown device).
Mozilla/5.0 (iPhone; CPU iPhone OS 12_1_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Snapchat/10.47.5.13 (iPhone10,1; iOS 12.1.2; gzip)
Seems like an iPhone
options is missing in the regex on this line:
Lines 80 to 82 in 2a8bd17
Hi, what is the correct way to report a bug or trigger some QA procedure here? In my instance, the module fails to recognise latest Chrome, Firefox and Edge on Windows 10 Pro 64. What test you like me to run and what report you want me to submit in order to clear this up? Please note that I am aware that it might be my very local issue, hence I am not really pushing it ahead as a confirmed bug. I would rather first run some tests before submitting the bug report, thought I am not sure what the bug fixing policy is optimal for you.
This package requires usage of useragent
in such a way that it always requires the usage of yamlparser
and request
too, but that is not declared in the package.json
.
You can see instructions for why those packages are necessary in their documentation right here https://github.com/3rd-Eden/useragent#api.
This will async load the database from the server and compile it to a proper JavaScript supported format. If it fails to compile or load it from the remote location it will just fall back silently to the shipped version. If you want to use this feature you need to add yamlparser and request to your package.json
npm install yamlparser --save
npm install request --save
Therefore yamlparser
and request
should be considered a hard dependency of this library. If I use this library without installing yamlparser
I cannot compile my application. It's essentially become an external dependency for this library, even though it really shouldn't be treated as such.
Module not found: Error: Can't resolve 'yamlparser'
in '/Users/user/Documents/workspace/application/node_modules/useragent/lib
I believe the final json should look like this
"dependencies": {
"useragent": "*",
"yamlparser": "*",
"request": "*"
},
Can you please add AdsBot also to the botlist?
"Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1 (compatible; AdsBot-Google-Mobile; +http://www.google.com/mobile/adsbot.html)"
Could this be added to the bot list?
const ua = 'Mozilla/5.0 (compatible; TrendsmapResolver/0.1)';
console.log(device(ua, {parseUserAgent: true} ))
Results in
{ parser:
DeviceParser {
options:
{ emptyUserAgentDeviceType: 'desktop',
unknownUserAgentDeviceType: 'phone',
botUserAgentDeviceType: 'bot',
carUserAgentDeviceType: 'car',
consoleUserAgentDeviceType: 'tv',
tvUserAgentDeviceType: 'tv',
parseUserAgent: true },
make_sure_parser_was_executed: [Function],
get_model: [Function],
get_type: [Function],
useragent:
Agent {
family: 'Other',
major: '0',
minor: '0',
patch: '0',
source: 'Mozilla/5.0 (compatible; TrendsmapResolver/0.1)' } },
type: 'phone',
model: 'Other',
is: [Function: is] }
Mozilla/5.0 (X11; u; Linux; C) AppleWebKit /533.3 (Khtml, like Gheko) QtCarBrowser Safari /533.3
XCode Simulator:
IOS 13.3 - Ipad (7th generation)
IOS 13.3 - Ipad Pro (11 -inch)
const express = require('express');
const router = express.Router();
router.get('/', function(req, res, next) {
const ua = req.headers['user-agent'];
const theDevice = device.useragent_is(ua);
console.log(theDevice.type);
res.render('index', { title: 'Express' });
});
desktop
tablet
Submitted by @reality in express-device repo
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]
Upgrade minimist to version 0.2.1 or later. For example:
"dependencies": {
"minimist": ">=0.2.1"
}
orβ¦
"devDependencies": {
"minimist": ">=0.2.1"
}
It would be nice to use the same library to detect devices on the server and on the client to write universal apps :)
I was thinking it might be nice to externalize the list of useragents to a separate module. That way your implementation is more clearly separated from the useragent data and updates should be easier.
Also, it'll be possible for other libraries to consume the list of useragents as well (which should attract more contributors and keep the list more up-to-date). A library like https://www.npmjs.com/package/useragent-list could suit as base and be modified to just json (so get rid of the xml), and to a structure that suits consumption by other libs (like express-useragent, who also mix useragent strings in their code).
What do you think?
Search for CrKey in the user-agent string
When I try to request my api with golang (By default, user agent is: "Go-http-client/1.1")
I have device type "phone", because my User-Agent is Unknown. But this is not a phone. I think this behaviour, when you set unknownUserAgentDeviceType: 'phone'
, is strange and wrong.
Can you add "Go-http-client" to desktop section?
Hi,
I am getting undefined for get_model().
Ex:
{ parser: DeviceParser { options: { emptyUserAgentDeviceType: 'desktop', unknownUserAgentDeviceType: 'phone', botUserAgentDeviceType: 'bot', carUserAgentDeviceType: 'car', parseUserAgent: false }, make_sure_parser_was_executed: [Function], get_model: [Function], get_type: [Function] }, type: 'phone', model: '', is: [Function: is] }
and my api response is : " "
empty for getmodel().
UserAgent is Mozilla/5.0 (Linux; Android 7.0; Redmi Note 4 Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.125 Mobile Safari/537.36
Great work!
Using webpack 2, I'm running into this error where the relative reference to package module in ./node_modules/device/lib/device.js breaks.
Seems normal as it looks for "package" in ./node_modules/device folder while it should be looking for it in ./node_modules.
One of our users has this user agent being sent from a desktop device (trying to get more specific information from them): Mozilla/5.0(WindowsNT6.1;rv:31.0)Gecko/20100101Firefox/31.0. Because there are no spaces it is being reported as unknown and set to the default value of phone.
The fix seems as easy as replacing ua.match(/Windows (NT|XP|ME|9)/) with ua.match(/Windows( )?(NT|XP|ME|9)/).
it is highly probable that a request with user agent "WinHTTP" comes from a scraper. In som e resources it is even said to be a part of the virus. Could you add it to the bot list please?
Some more info:
AWS CloudFront groups incoming user agents to these values:
CloudFront-Is-Desktop-Viewer
CloudFront-Is-Mobile-Viewer
CloudFront-Is-SmartTV-Viewer
CloudFront-Is-Tablet-Viewer
Maybe we can also add detection support for those in device
library?
Unknown bots and appstatus requests are coming back as 'phone'
@macinjosh32 submitted the following issue on express-device repo:
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=enSeems 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?
Hello,
Do you consider adding bingbot detection? You can check their useragent string here https://www.bing.com/webmaster/help/which-crawlers-does-bing-use-8c184ec0
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.