Giter Club home page Giter Club logo

device-detector-js's People

Contributors

alexbeauchemin avatar dependabot[bot] avatar etienne-martin avatar jmaitrehenry avatar koderfunk avatar kozmanbalint avatar markehr avatar seawind543 avatar themezv avatar whimsicaldreamer 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar

device-detector-js's Issues

Update of Matomo Device Detector

Hey Etienne,

Thanks for this NodeJs port of Matomo Device Detector.

So I have two questions ?

  1. How do we ensure that this port has all the new changes from the Matomo Device Detector ? Is there a way to manually trigger the update ?

  2. Looks like Matomo has released a new minor version 3.11.2. Do you need to update your fork of the PHP Matomo Device Detector library to get the latest changes ?

https://github.com/matomo-org/device-detector/releases

Regards,
Arvin

How to use in old legacy project

Hallo how can I use this module with my old project without typescript, ES6 Classes / Imports, webpack?

I have only this ES6 classes in this folders:
image

Fail to detect Opera Mini Browser

The module does not work correctly on Opera Mini mobile
Tested on mobile Opera Mini
It returns
{"client":{"type":"browser","name":"Mobile Safari","version":"","engine":"WebKit","engineVersion":"605.1"},"os":{"name":"iOS","version":"12.2","platform":""},"device":{"type":"smartphone","brand":"Apple","model":"iPhone"},"bot":null}
So basically the module detects this is Safari Mobile instead of Safari

https://gist.github.com/ireade/10fe4b3c1e1caa9751a3 <= this might help detect Opera Mini

Errors prompted when using webpack build

Error prompted when using webpack build. My version of webpack is 3.10.0, and typescript is 3.5.0
The content of the prompt:
Failed to compile.
Failed to minimize the bundle. Error: static/js/common.3.0.0.9 aad8.js from Uglify Js
Invalid assignment [static/js/common.3.0.0.9aad8.js:30539,48]
...

Release info for 2.2.1?

Unless if I missed something, 2.2.1 has been released to npm without any release documentation of any kind, not even so much as a git tag. What changed?

Optimization: cache RegExp instances

We found out that a simple change to user-agent.ts file could provide a significant speedup: full.test.ts completes in 10 seconds instead of 19 on our machines.

While this is not significant in browser scenario, it becomes really important in server-side setting (i.e. we saw an increase of several ms on our servers after integrating the library).

We are happy to submit a pull request with the changes that are currently sitting in our fork: lunalabsltd@2dd6a99

Regex error

I got this error when using this library:

/home/travis/build/diablomedia/useragent-parser-comparison/parsers/device-detector-js-1/node_modules/device-detector-js/dist/parsers/client/browser.js:50
                    const match = RegExp(browserEngine.regex, "i").exec(userAgent);
                                  ^
SyntaxError: Invalid regular expression: /(?<!like )Gecko/: Invalid group
    at RegExp (<anonymous>)
    at BrowserParser.parse (/home/travis/build/diablomedia/useragent-parser-comparison/parsers/device-detector-js-1/node_modules/device-detector-js/dist/parsers/client/browser.js:50:35)
    at ClientParser.parse (/home/travis/build/diablomedia/useragent-parser-comparison/parsers/device-detector-js-1/node_modules/device-detector-js/dist/parsers/client/index.js:28:39)
    at DeviceDetector.parse (/home/travis/build/diablomedia/useragent-parser-comparison/parsers/device-detector-js-1/node_modules/device-detector-js/dist/index.js:32:43)
    at Object.<anonymous> (/home/travis/build/diablomedia/useragent-parser-comparison/parsers/device-detector-js-1/scripts/parse.js:5:10)
    at Module._compile (module.js:635:30)
    at Object.Module._extensions..js (module.js:646:10)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)
    at Function.Module._load (module.js:489:3)

used Node.js version: 8.9
used library version: 1.1.1

[BUG] app is crashing on mac os safari

Hi, it seems like you didn't test it correctly!!!
My userAgent:

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Safari/605.1.15

image

How to use in browser

For people that don't know npm/nodejs, how to use/build the package so I can import it as minified in a browser ?

How to import library?

How to import the library into my typescript code?

  1. When I write
import DeviceDetector from 'device-detector-js';

I get an error "no default export".

  1. When I try
import * as DeviceDetector from 'device-detector-js';

It also shows an error and does not work.

  1. Third attempt:
import { DeviceDetector }  from 'device-detector-js';

Error: there is no exported member "DeviceDetector"

Example in README.md shows require syntax, but I want to use ES6 modules syntax.
Could you please and an example with ES6 modules syntax into README.md?

Incorrect iPhone models for mobile user agents

⚠️ Missing/incorrect detections should be reported at https://github.com/matomo-org/device-detector/issues instead of this repo.

Tried to report at the above attached link. Posting here too as not sure if the package handles parsing mobile app based user agents.

Mobile app device model version seems to be incorrect for the below and similar app based user agents. iPhone12 reports device as iPhone 11 Pro Max and just iPhone respectively.

  • Testapp/2.148.2 (com.testapp.omega; build:20210204501; iPhone12,5; iOS 14.2; scale:3.0)
  • Testapp/2.149.3 (com.testapp.omega; build:20210204501; iPhone13,5; iOS 14.2; scale:3.0)

Missing dist/index.js

Version 2.2.3 , 2.2.4
Could not found to dist/index.js,,

so my app is crash down..!!
please fix it!

Failing Tests

Following the steps to update the library, certain tests fail. Not sure how to fix them.
The failing tests are with the yandex browser only.

2
3
1

Caching is not working

Hey Etienne,

This is Arvin again. We were testing the caching aspect of the device detection. I don't think its working. We tried console.log of the cached result, its always empty even when the cache option is set to several minutes.

installation fails

I tried to install this repo and got this error:

> [email protected] install /home/developer/projects/useragent-parser-comparison/parsers/device-detector-js-1/node_modules/device-detector-js
> sh install.sh

info git https://github.com/etienne-martin/matomo-device-detector into device-detector
Username for 'https://github.com': mimmi20
Password for 'https://[email protected]':
ERR! remote: Repository not found.

ERR! fatal: repository 'https://github.com/etienne-martin/matomo-device-detector/' not found

cp: ..

npm version: 5.6.0
node version: 9.11.2

Additional Question: Why is the installation script asking for a Github login? Should it work without?

Performance issue

Here's a sample code:

  const deviceDetector = new DeviceDetector();
  const startPoint = performance.now();
  deviceDetector.parse('');
  console.log(`Time elapsed #1: ${Math.trunc(performance.now() - startPoint)}ms`);
  deviceDetector.parse('');
  console.log(`Time elapsed #2: ${Math.trunc(performance.now() - startPoint)}ms`);
  deviceDetector.parse('');
  console.log(`Time elapsed #3: ${Math.trunc(performance.now() - startPoint)}ms`);

Here's the result:

Time elapsed #1: 287ms
Time elapsed #2: 511ms
Time elapsed #3: 514ms

So, I see here a few issues:

  • second run takes almost as much time as the first one, but starting with third everything starts to work faster; given there's some kind of lazy cache, I'd expect the second run already be fast;
  • overall question - is it OK that a fully locally loaded library takes ~280ms of CPU time to process a simple input string? For the context, I run it on AMD Ryzen 7 5800HS - which is a relatively capable CPU

YAML Exception

Got the following error while running fixtures. Didn't get the time to debug, so thought of sharing.

Annotation 2020-01-13 225435

Version parse error

Version parse result incorrect, when the Minor_Version_Number is 0. Like picture below:
detector bug
Expect:
detector bug 2

[bug with the JS implementation] device type and model is null in phone, but has value in computer

Mozilla/5.0 (iPhone; CPU iPhone OS 14_0_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0 Mobile/15E148 Safari/604.1

Open https://lx3rzx16x9.codesandbox.io/ in phone:

"device":{
  "type":"",
  "brand":"Apple",
  "model":"",
}

Open https://lx3rzx16x9.codesandbox.io/ in pc, then copy the user agent above into the input:

"device":{
  "type":"smartphone",
  "brand":"Apple",
  "model":"iPhone",
}

Reply from Member of device-detector repository:

Hi,

https://lx3rzx16x9.codesandbox.io/ uses https://github.com/etienne-martin/device-detector-js which is an implementation in JS that only shares the rules list.

The PHP version detects a "deviceName" of "smartphone":

https://devicedetector.lw1.at/Mozilla%2F5.0%20(iPhone;%20CPU%20iPhone%20OS%2014_0_1%20like%20Mac%20OS%20X)%20AppleWebKit%2F605.1.15%20(KHTML,%20like%20Gecko)%20Version%2F14.0%20Mobile%2F15E148%20Safari%2F604.1

In case this is a bug with the JS implementation, I'd recommend you to open an issue there.

See matomo-org/device-detector#6067

Extending device detector to use custom parsers

Is there a way to extend this library to parse custom user with a provided regex? In the original library it can be done by extending the ClientParserAbstract class and providing a fixture file with the regex. I was hoping whether it could be done in this library, out of the box.

May be something like:

const DeviceDetector = new DeviceDetector({
    skipBotDetection: false,
    versionTruncation: 1,
    customParser: [
        { type: "mobile_app", name: "MyApp", parser: "MyApp(?:[ /]([\d\.]+))?", version: "$1" }
    ],
});

Whats App not detected

The bots.json files require an entry for What's App.

Here is an example of a user agent. I was able to work around this (without forking) just by testing the string for "WhatsApp" but it might be nice to get into this package.

WhatsApp/2.16.259 Mozilla/5.0(Android/4.3 Device/GalaxyS3) AppleWebKit/537.36 (KHTML, like Gecko)

typings

Hallo!

I think, typings folder should contain only *.d.tsfiles and not any js files

image

Same is for utils and parsers folder...

And I think, it will be better to have only one file ./types/index.d.ts, which contain all public interfaces.

Does not work on IPad 5,3

⚠️ Missing/incorrect detections should be reported at https://github.com/matomo-org/device-detector/issues instead of this repo.

Issue:

Detector does not work on IPad 5,3. Though it works fine in other IOs devices , Mac's also doesn't seems to have the same problem, so it only occurs on Ipad 5,3

Expected behaviour:

Print the device data as shown in the example.

Actual behaviour:

The library simply breaks the script and stop the others JS that needs to run after.

Code example:

import DeviceDetector from "device-detector-js";

const deviceDetector = new DeviceDetector();

function printDevice(deviceData) {
  const device = deviceDetector.parse(deviceData);
  return device;
}

window.deviceData = printDevice;

Outputs and Logs:

Unfortunately I have no access to any Mac's, and because of that i cannot see any debug log.

User Agent detection works in Matomo but bot Device Detector JS

Hey Etienne,

While using and testing this package, we have found some User agent get detected in devicedetector.net but not with device detector js. seems like mobiles.json needs to update to latest version to match the matomo mobiles.yml file

eg:
Mozilla/5.0 (Linux; Android 8.0.0; ANE-LX1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.99 Mobile Safari/537.36

device detected in:
http://devicedetector.net/?ua=Mozilla%2F5.0+%28Linux%3B+Android+8.0.0%3B+ANE-LX1%29+AppleWebKit%2F537.36+%28KHTML%2C+like+Gecko%29+Chrome%2F71.0.3578.99+Mobile+Safari%2F537.36%09Mozilla%2F5.0+%28Linux%3B+Android+8.0.0%3B+LM-G710%29+AppleWebKit%2F537.36+%28KHTML%2C+like+Gecko%29+Chrome%2F71.0.3578.99+Mobile+Safari%2F537.36

but not in https://lx3rzx16x9.codesandbox.io/

export declared with export = DeviceDetector; forces me to use 'allowSyntheticDefaultImports'

DeviceDetector is declared with export = DeviceDetector; and no default export is specified.

Our project was configured without 'allowSyntheticDefaultImports'.
With this configuration:

  1. an IDE like webstorm will automatically import DeviceDetector with the line
import * as React from "react";

which will work fine in development, but when the project is built, there will be exceptions, the DeviceDetector constructor will not be found.

Trying to import DeviceDetector with this configuration like this

import DeviceDetector from "device-detector-js";

leads to the following typescript error:

⚠️ Missing/incorrect detections should be reported at https://github.com/matomo-org/device-detector/issues instead of this repo.
TS1259: Module '"C:/dev/viuport/client/node_modules/device-detector-js/dist/index"' can only be default-imported using the 'allowSyntheticDefaultImports' flag index.d.ts(34, 1): This module is declared with using 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag.

see also https://www.typescriptlang.org/tsconfig#allowSyntheticDefaultImports

I would instead endorse exporting DeviceDetector as default, for example like this

export default class DeviceDetector {
// ...

weird bug: error handlig in express was no longer working

Super weird bug... my error throwing was not working anymore only in the authentication module. Killed my self to understand why until I commented every line of extra code and pinpointed the error on device-detector-js.

Do you have some error handler that is missing an next() or something similar?

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.