GithubHelp home page GithubHelp logo

rguerreiro / device Goto Github PK

View Code? Open in Web Editor NEW
79.0 79.0 27.0 293 KB

Device type detection library based on the useragent string. Refactored from my express-device repo.

License: MIT License

JavaScript 100.00%

device's People

Contributors

boreplusplus avatar cliftonc avatar fmmsilva avatar kelp404 avatar lennym avatar martincad avatar mettin avatar rguerreiro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

device's Issues

No iPhone rule

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:

device/lib/device.js

Lines 80 to 82 in 2a8bd17

} else if (ua.match(/BOLT|Fennec|Iris|Maemo|Minimo|Mobi|mowser|NetFront|Novarra|Prism|RX-34|Skyfire|Tear|XV6875|XV6975|Google Wireless Transcoder/i)) {
// if user agent is unique phone User Agent
return 'phone';

Bug Fix Reporting and QA Guides?

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.

Does Not Declare Dependency `yamlparser` or `request`

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": "*"
  },

AdsBot from Google is detected as "phone"

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)"

TrendsmapResolver is not detected as a bot

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] }

Support car device type

Mozilla/5.0 (X11; u; Linux; C) AppleWebKit /533.3 (Khtml, like Gheko) QtCarBrowser Safari /533.3

Return desktop for Ipad Simulator from XCode

Target Device:

XCode Simulator:
IOS 13.3 - Ipad (7th generation)
IOS 13.3 - Ipad Pro (11 -inch)

Code Snippet:

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' });
});

Actual Result

desktop

Expected Result

tablet

wget shows up as a phone

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]

[Bug] Build issues with Angular project (webpack)

Webpack in an angular project seems to have issues with json imports when the extension of the file is not added in the require, as well as the package useragent having issues with yamlparser being in the wrong dependency property (is in dev deps, not in normal ones where it should).

screenshot from 2018-02-15 17-50-31

Upgrade minimist

Upgrade minimist to version 0.2.1 or later. For example:

"dependencies": {
"minimist": ">=0.2.1"
}

or…

"devDependencies": {
"minimist": ">=0.2.1"
}

Universal support?

It would be nice to use the same library to detect devices on the server and on the client to write universal apps :)

Externalize list of useragents

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?

Go-http-client wrong device detect

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?

getting empty response for get_model()!

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

Error: Cannot find module "../package"

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.

Desktop user agent without spaces reported as phone

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)/).

CloudFront headers

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

(source)

Maybe we can also add detection support for those in device library?

Googlebot on smartphone classified as "phone" instead of "bot"

@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=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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.