Giter Site home page Giter Site logo

intoli / user-agents Goto Github PK

View Code? Open in Web Editor NEW
917.0 12.0 49.0 376.77 MB

A JavaScript library for generating random user agents with data that's updated daily.

License: Other

JavaScript 22.06% Emacs Lisp 2.32% TypeScript 75.61%
user-agent user-agent-spoofer random randomization javascript navigator browsers browser-automation web-scraping

user-agents's Introduction

User Agents

Build Status Build Status License NPM Version          Tweet Share on Facebook Share on Reddit Share on Hacker News

User-Agents is a JavaScript package for generating random User Agents based on how frequently they're used in the wild. A new version of the package is automatically released every day, so the data is always up to date. The generated data includes hard to find browser-fingerprint properties, and powerful filtering capabilities allow you to restrict the generated user agents to fit your exact needs.

Web scraping often involves creating realistic traffic patterns, and doing so generally requires a good source of data. The User-Agents package provides a comprehensive dataset of real-world user agents and other browser properties which are commonly used for browser fingerprinting and blocking automated web browsers. Unlike other random user agent generation libraries, the User-Agents package is updated automatically on a daily basis. This means that you can use it without worrying about whether the data will be stale in a matter of months.

Generating a realistic random user agent is as simple as running new UserAgent(), but you can also easily generate user agents which correspond to a specific platform, device category, or even operating system version. The fastest way to get started is to hop down to the Examples section where you can see it in action!

Installation

The User Agents package is available on npm with the package name user-agents. You can install it using your favorite JavaScript package manager in the usual way.

# With npm: npm install user-agents
# With pnpm: pnpm install user-agents
# With yarn:
yarn add user-agents

Examples

The User-Agents library offers a very flexible interface for generating user agents. These examples illustrate some common use cases, and show how the filtering API can be used in practice.

Generating a Random User Agent

The most basic usage involves simply instantiating a UserAgent instance. It will be automatically populated with a random user agent and browser fingerprint.

import UserAgent from 'user-agents';


const userAgent = new UserAgent();
console.log(userAgent.toString());
console.log(JSON.stringify(userAgent.data, null, 2));

In this example, we've generated a random user agent and then logged out stringified versions both the userAgent.data object and userAgent itself to the console. An example output might look something like this.

Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36
{
  "appName": "Netscape",
  "connection": {
    "downlink": 10,
    "effectiveType": "4g",
    "rtt": 0
  },
  "platform": "Win32",
  "pluginsLength": 3,
  "vendor": "Google Inc.",
  "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36",
  "viewportHeight": 660,
  "viewportWidth": 1260,
  "deviceCategory": "desktop",
  "screenHeight": 800,
  "screenWidth": 1280
}

The userAgent.toString() call converts the user agent into a string which corresponds to the actual user agent. The data property includes a randomly generated browser fingerprint that can be used for more detailed emulation.

Restricting Device Categories

By passing an object as a filter, each corresponding user agent property will be restricted based on its values.

import UserAgent from 'user-agents';

const userAgent = new UserAgent({ deviceCategory: 'mobile' })

This code will generate a user agent with a deviceCategory of mobile. If you replace mobile with either desktop or tablet, then the user agent will correspond to one of those device types instead.

Generating Multiple User Agents With The Same Filters

There is some computational overhead involved with applying a set of filters, so it's far more efficient to reuse the filter initialization when you need to generate many user agents with the same configuration. You can call any initialized UserAgent instance like a function, and it will generate a new random instance with the same filters (you can also call userAgent.random() if you're not a fan of the shorthand).

import UserAgent from 'user-agents';

const userAgent = new UserAgent({ platform: 'Win32' });
const userAgents = Array(1000).fill().map(() => userAgent());

This code example initializes a single user agent with a filter that limits the platform to Win32, and then uses that instance to generate 1000 more user agents with the same filter.

Regular Expression Matching

You can pass a regular expression as a filter and the generated user agent will be guaranteed to match that regular expression.

import UserAgent from 'user-agents';

const userAgent = new UserAgent(/Safari/);

This example will generate a user agent that contains a Safari substring.

Custom Filter Functions

It's also possible to implement completely custom logic by using a filter as a function. The raw userAgent.data object will be passed into your function, and it will be included as a possible candidate only if your function returns true. In this example, we'll use the useragent package to parse the user agent string and then restrict the generated user agents to iOS devices with an operating system version of 11 or greater.

import UserAgent from 'user-agents';
import { parse } from 'useragent';

const userAgent = new UserAgent((data) => {
  const os = parse(data.userAgent).os;
  return os.family === 'iOS' && parseInt(os.major, 10) > 11;
});

The filtering that you apply here is completely up to you, so there's really no limit to how specific it can be.

Combining Filters With Arrays

You can also use arrays to specify collections of filters that will all be applied. This example combines a regular expression filter with an object filter to generate a user agent with a connection type of wifi, a platform of MacIntel, and a user agent that includes a Safari substring.

import UserAgent from 'user-agents';

const userAgent = new UserAgent([
  /Safari/,
  {
    connection: {
      type: 'wifi',
    },
    platform: 'MacIntel',
  },
]);

This example also shows that you can specify both multiple and nested properties on object filters.

API

class: UserAgent([filters])

  • filters <Array, Function, Object, RegExp, or String> - A set of filters to apply to the generated user agents. The filter specification is extremely flexible, and reading through the Examples section is the best way to familiarize yourself with what sort of filtering is possible.

UserAgent is an object that contains the details of a randomly generated user agent and corresponding browser fingerprint. Each time the class is instantiated, it will randomly populate the instance with a new user agent based on the specified filters. The instantiated class can be cast to a user agent string by explicitly calling toString(), accessing the userAgent property, or implicitly converting the type to a primitive or string in the standard JavaScript ways (e.g. `${userAgent}`). Other properties can be accessed as outlined below.

userAgent.random()

  • returns: <UserAgent>

This method generates a new UserAgent instance using the same filters that were used to construct userAgent. The following examples both generate two user agents based on the same filters.

// Explicitly use the constructor twice.
const firstUserAgent = new UserAgent(filters);
const secondUserAgent = new UserAgent(filters);
// Use the `random()` method to construct a second user agent.
const firstUserAgent = new UserAgent(filters);
const secondUserAgent = firstUserAgent.random();

The reason to prefer the second pattern is that it reuses the filter processing and preparation of the data for random selection. Subsequent random generations can easily be over 100x faster than the initial construction.

userAgent()

  • returns: <UserAgent>

As a bit of syntactic sugar, you can call a UserAgent instance like userAgent() as a shorthand for userAgent.random(). This allows you to think of the instance as a generator, and lends itself to writing code like this.

const generateUserAgent = new UserAgent(filters);
const userAgents = Array(100).fill().map(() => generateUserAgent());

userAgent.toString()

  • returns: <String>

Casts the UserAgent instance to a string which corresponds to the user agent header. Equivalent to accessing the userAgent.userAgent property.

userAgent.data

The userAgent.data contains the randomly generated fingerprint for the UserAgent instance. Note that each property of data is also accessible directly on userAgent. For example, userAgent.appName is equivalent to userAgent.data.appName.

Versioning

The project follows the Semantic Versioning guidelines. The automated deployments will always correspond to patch versions, and minor versions should not introduce breaking changes. It's likely that the structure of user agent data will change in the future, and this will correspond to a new major version.

Please keep in mind that older major versions will cease to be updated after a new major version is released. You can continue to use older versions of the software, but you'll need to upgrade to get access to the latest data.

Acknowledgements

The user agent frequency data used in this library is generously provided by Intoli, the premier residential and smart proxy provider for web scraping. The details of how the data is updated can be found in the blog post User-Agents — A random user agent generation library that's always up to date.

If you have a high-traffic website and would like to contribute data to the project, then send us an email at [email protected]. Additional data sources will help make the library more useful, and we'll be happy to add a link to your site in the acknowledgements.

Contributing

Contributions are welcome, but please follow these contributor guidelines outlined in CONTRIBUTING.md.

License

User-Agents is licensed under a BSD 2-Clause License and is copyright Intoli, LLC.

user-agents's People

Contributors

acefire6 avatar sangaline avatar user-agents 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  avatar

user-agents's Issues

Security Vulnerability: CVE-2023-26139 underscore-keypath Prototype Pollution

Description

I have identified a security vulnerability in one of the dependencies used by user-agents v1.0.1444. The dependency underscore-keypath is vulnerable to Prototype Pollution, as described in CVE-2023-26139.

Details

  • Affected Version: user-agents v1.0.1444
  • Vulnerable Dependency: underscore-keypath
  • CVE: CVE-2023-26139
  • Impact: Prototype Pollution can allow an attacker to inject arbitrary properties into existing objects. This can lead to various types of security vulnerabilities such as bypassing security checks or potentially unauthorized execution of code.

Steps to Reproduce

  1. Install the user-agents package using npm with the version v1.0.1444.
  2. Run npm audit in the project directory.

Thank you for your attention to this matter.

Python version

Hello @intoli,

Thanks for the very useful tool. I was wondering if you'd accept to have your library replicated in python (I can do it if you want), as I would very much like to have your user-agents available in a python environment.

Have a great day,

Update user agent data

" Unlike other random user agent generation libraries, the User-Agents package is updated automatically on a daily basis."

On NPM, however it does not seem to have been updated for a while.

Could you update de data ?
Thanks :)

UserAgent is not defined

Just installed user-agents. Pasted in the basic example, and const userAgent = new UserAgent(); returns ReferenceError: UserAgent is not defined

I logged the variable which required user-agents and the package exists and is installed correctly. I'd hope this is an issue on my end because this seems like a promising package.

Thanks.

Lacks normal amount of Firefox instances

I only see 6 instances of the word 'Firefox' among the user agents. This would result in a fingerprint in itself after multiple requests due to the unnatural distribution of browsers.

Bad data and inconsistencies

Thanks for the great lib! I noticed some bad UAs coming up with my filters from time to time, which might caused by fake generic UAs being collected and leaking into releases. Since the core value of this lib is to provide realistic UAs it would be good to filter the bad ones out all together.

  1. There's literally the following UA with "{userAgent}" value in v1.0.343:
{appName:"Netscape",connection:{downlink:10,effectiveType:"4g",rtt:50},platform:"MacIntel",pluginsLength:3,vendor:"Google Inc.",userAgent:"{userAgent}",viewportHeight:670,viewportWidth:1190,deviceCategory:"desktop",screenHeight:900,screenWidth:1440,weight:3278510796810622e-20}`
  1. There're a few wrongfully identified UAs, here's the platform is MacIntel, but should be Linux:
{appName:"Netscape",connection:{downlink:4.5,effectiveType:"4g",rtt:100},platform:"MacIntel",pluginsLength:3,vendor:"Google Inc.",userAgent:'"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.39 Safari/537.36"',viewportHeight:800,viewportWidth:1670,deviceCategory:"desktop",screenHeight:1050,screenWidth:1680,weight:6634456214284333e-20}
  1. iPad with deviceCategory: 'desktop' and platform: 'MacIntel':
{appName:"Netscape",connection:{downlink:8,effectiveType:"4g",rtt:150},platform:"MacIntel",pluginsLength:0,vendor:"Google Inc.",userAgent:"Mozilla/5.0 (iPad; CPU OS 11_0 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) Version/11.0 Mobile/15A5341f Safari/604.1",viewportHeight:810,viewportWidth:1410,deviceCategory:"desktop",screenHeight:1050,screenWidth:1680,weight:8770374263814142e-20}

Invalid header in package

In recent versions of the package, a header containing emoji is included (posted below). This results in errors with lots of clients, including node-fetch and chromium fetch, with an error like this:

VM245:2 Uncaught TypeError: Failed to execute 'fetch' on 'Window': Failed to read the 'headers' property from 'RequestInit': String contains non ISO-8859-1 code point.
    at <anonymous>:1:17

Can you avoid including user-agents outside of the ascii range?

Header:

  {
    "appName": "Forget about App Name.",
    "connection": {
      "downlink": 10,
      "effectiveType": "4g",
      "rtt": 50
    },
    "platform": "This is CODM platform",
    "pluginsLength": 0,
    "vendor": "Oja Vendor Agba. 😎",
    "userAgent": "SUPERSTAR! the guy dey form superstar  Chee..... 😹",
    "viewportHeight": 660,
    "viewportWidth": 1350,
    "deviceCategory": "desktop",
    "screenHeight": 768,
    "screenWidth": 1366,
    "weight": 0.00006628526257710449
  },

how would this be implemented in puppeteer?

I'm trying to get this implemented with puppeteer, what am I doing wrong?

const UserAgent = require('user-agents');
// set UserAgent
const userAgent = new UserAgent();
await page.setUserAgent(userAgent);

getting this error

(node:19627) UnhandledPromiseRejectionWarning: Error: Protocol error (Network.setUserAgentOverride): Invalid parameters userAgent: string value expected

Get old user-agents

Currently the module generates mostly latest user-agents. Is there any possibility to get random old user-agents?

TypeError: UserAgent is not a constructor

later than this version [email protected] i get this error "TypeError: UserAgent is not a constructor" i dont know what it causes

import UserAgent from 'user-agents';
const userAgent = new UserAgent();
console.log(userAgent.toString())
console.log(userAgent.data)

Firefox

There's only 2 entries for Firefox based user agents, this is a very small pool of relevant user agents, I can contribute lots of new Firefox user agents, if that's the right way to do it. (Manually)

about the most popular browser

can you make a list of the most popular browser user agent of 2019 (top 50 or 100?), and yearly update that? for another repo sqlmap (google translated ^^''

Better documentation about the user-agents given randomly by this lib

Might be good to add this to the documentation :

  • user-agent strings provided is not "random" because user-agents.json.gz contains browser fingerprints not user-agents strings so it will give you a representation of what is most used at the time period depending of the version of the lib.
  • the db is updated in full not incremental, so old UA are ventilated

For example :

Top user agent for v1.0.378

   3014     "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36",
   1096     "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36",
    417     "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36",
    410     "userAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36",
    384     "userAgent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36",
    322     "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36",
    289     "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36",
    273     "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1.2 Safari/605.1.15",
    195     "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36",
    194     "userAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36",
    144     "userAgent": "Mozilla/5.0 (iPhone; CPU iPhone OS 12_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1.2 Mobile/15E148 Safari/604.1",
    106     "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36",
     96     "userAgent": "Mozilla/5.0 (iPhone; CPU iPhone OS 12_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1.2 Mobile/15E148 Safari/604.1",
     95     "userAgent": "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36",
     95     "userAgent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36",
     94     "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36",
     86     "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1.1 Safari/605.1.15",
     86     "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36",
     84     "userAgent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36",
     78     "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36",

Top user-agent for the last version (master)

   1668     "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36",
   1378     "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36",
    465     "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36",
    403     "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36",
    383     "userAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36",
    260     "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36",
    237     "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36",
    197     "userAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36",
    151     "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.4 Safari/605.1.15",
    142     "userAgent": "Mozilla/5.0 (iPhone; CPU iPhone OS 13_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.4 Mobile/15E148 Safari/604.1",
    126     "userAgent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36",
    113     "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36",
    110     "userAgent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36",
    106     "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36",
     96     "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36",
     80     "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36",
     66     "userAgent": "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36",
     64     "userAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/79.0.3945.79 Chrome/79.0.3945.79 Safari/537.36",
     64     "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36",
     62     "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36",

You can reproduce with this command
zcat user-agents.json.gz | grep userAgent | sort | uniq -c | sort -nr | head -20

How to properly setup in puppeteer?

How to properly imitate browser in puppeteer? Currently I use this:

const puppeteer = require('puppeteer-extra')
const pluginStealth = require("puppeteer-extra-plugin-stealth");
(async () => {
  console.log(proxy.url);
  puppeteer.launch({
    headless: true,
    ignoreHTTPSErrors: true,
    args: [
      `--window-size=${ua.data.viewportWidth},${ua.data.viewportHeight + windowFrame}`,
    ]
  }).then(async browser => {
puppeteer.use(pluginStealth({
  enabledEvasions: new Set([
    'chrome.runtime',
    'console.debug',
    'navigator.languages',
    'navigator.permissions',
    'navigator.webdriver',
    'navigator.plugins',
    'window.outerdimensions',
    'webgl.vendor',
    'user-agent'
  ])
}));

    const page = await browser.newPage();
    await page.setExtraHTTPHeaders({
      'Accept-Language': 'en-US,en;q=0.9',
      'Accept-Encoding': 'gzip, deflate, br'
    });

    await page.setViewport({
      width: ua.data.viewportWidth,
      height: ua.data.viewportHeight
    });
    await page.setUserAgent(ua.toString());
    await page.evaluateOnNewDocument((uad, windowFrame) => {
      Object.defineProperty(screen, 'width', {get: () => uad.screenWidth});
      Object.defineProperty(screen, 'height', {get: () => uad.screenHeight});
      Object.defineProperty(window, 'outerWidth', {get: () => uad.viewportWidth});
      Object.defineProperty(window, 'outerHeight', {get: () => uad.viewportHeight + windowFrame});
      Object.defineProperty(navigator, 'languages', {get: () => ['en-US', 'en']});
      Object.defineProperty(navigator, 'language', {get: () => ['en-US']});
      Object.defineProperty(navigator, 'connection', {get: () => uad.connection});
      Object.defineProperty(navigator, 'cpuClass', {get: () => uad.cpuClass});
      Object.defineProperty(navigator, 'oscpu', {get: () => uad.oscpu});
      Object.defineProperty(navigator, 'platform', {get: () => uad.platform});
      Object.defineProperty(navigator.plugins, 'length', {get: () => uad.pluginsLength});
      Object.defineProperty(navigator, 'vendor', {get: () => uad.vendor});

      if (uad.appName !== 'Chrome') {
        Object.defineProperty(window, 'chrome', {get: () => undefined});
      }
    }, ua.data, windowFrame);

    await page.goto('https://my-site.com/'), {waitUntil: 'networkidle0'};
})

I test it by watching realtime google analytics in realtime.
If I remove setUserAgent and evaluateOnNewDocument (though using raw pluginStealth) — mu hit displays at GA realtime report. If I enable all this — GA doesn't report hit — seems to be detected as a bot and ignored.

What am I doing wrong?

[TypeScript] Won't work without `esModuleInterop` flag

Hi,

Great module. Thank you for it.

However, I'm facing issues while using it in a TypeScript project. I have tried the following approaches:

  • As per README
    (import UserAgent from 'user-agents';)
    I get TypeError: user_agents_1.default is not a constructor error

  • Based on #10
    (import * as UserAgent from 'user-agents';)
    I get TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export. error

I investigated and I tried to learn more about the issue, you should check this StackOverflow.

Is it possible to fix it in the near-term so as to avoid using esModuleInterop flag?

SyntaxError: Unexpected identifier on use

I've been fighting with this for a couple of hours and I can't seem to work out why I can't get the simple example to execute.

I'm sure I'm doing something incredibly stupid, so any help you could provide would be appreciated.

I'm currently using Node 10.11.0 and I'm getting the following error from the example:

import UserAgent from "user-agents";

const userAgent = new UserAgent();
console.log(userAgent.toString());
console.log(JSON.stringify(userAgent.data, null, 2));
node index.js
~/apps/bunraku/spike/index.js:1
(function (exports, require, module, __filename, __dirname) { import UserAgent from "user-agents";
                                                                     ^^^^^^^^^

SyntaxError: Unexpected identifier
    at new Script (vm.js:79:7)
    at createScript (vm.js:251:10)
    at Object.runInThisContext (vm.js:303:10)
    at Module._compile (internal/modules/cjs/loader.js:657:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at startup (internal/bootstrap/node.js:279:19)

Here is my package.json:

{
  "name": "bunraku-spike",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "node index.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "puppeteer": "^1.8.0",
    "user-agents": "^1.0.28"
  },
  "devDependencies": {}
}

And my package-lock.json:

{
  "name": "bunraku-spike",
  "version": "1.0.0",
  "lockfileVersion": 1,
  "requires": true,
  "dependencies": {
    "agent-base": {
      "version": "4.2.1",
      "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-4.2.1.tgz",
      "integrity": "sha512-JVwXMr9nHYTUXsBFKUqhJwvlcYU/blreOEUkhNR2eXZIvwd+c+o5V4MgDPKWnMS/56awN3TRzIP+KoPn+roQtg==",
      "requires": {
        "es6-promisify": "^5.0.0"
      }
    },
    "async-limiter": {
      "version": "1.0.0",
      "resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.0.tgz",
      "integrity": "sha512-jp/uFnooOiO+L211eZOoSyzpOITMXx1rBITauYykG3BRYPu8h0UcxsPNB04RR5vo4Tyz3+ay17tR6JVf9qzYWg=="
    },
    "balanced-match": {
      "version": "1.0.0",
      "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
      "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c="
    },
    "brace-expansion": {
      "version": "1.1.11",
      "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
      "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
      "requires": {
        "balanced-match": "^1.0.0",
        "concat-map": "0.0.1"
      }
    },
    "buffer-from": {
      "version": "1.1.1",
      "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz",
      "integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A=="
    },
    "concat-map": {
      "version": "0.0.1",
      "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
      "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
    },
    "concat-stream": {
      "version": "1.6.2",
      "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz",
      "integrity": "sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==",
      "requires": {
        "buffer-from": "^1.0.0",
        "inherits": "^2.0.3",
        "readable-stream": "^2.2.2",
        "typedarray": "^0.0.6"
      }
    },
    "core-util-is": {
      "version": "1.0.2",
      "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
      "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac="
    },
    "debug": {
      "version": "3.2.5",
      "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.5.tgz",
      "integrity": "sha512-D61LaDQPQkxJ5AUM2mbSJRbPkNs/TmdmOeLAi1hgDkpDfIfetSrjmWhccwtuResSwMbACjx/xXQofvM9CE/aeg==",
      "requires": {
        "ms": "^2.1.1"
      }
    },
    "docopt": {
      "version": "0.6.2",
      "resolved": "https://registry.npmjs.org/docopt/-/docopt-0.6.2.tgz",
      "integrity": "sha1-so6eIiDaXsSffqW7JKR3h0Be6xE="
    },
    "dot-json": {
      "version": "1.0.4",
      "resolved": "https://registry.npmjs.org/dot-json/-/dot-json-1.0.4.tgz",
      "integrity": "sha1-tcWBjrUmp5F6wC3wF/6fujexEZU=",
      "requires": {
        "docopt": "~0.6.2",
        "underscore-keypath": "~0.0.22"
      }
    },
    "es6-promise": {
      "version": "4.2.5",
      "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.5.tgz",
      "integrity": "sha512-n6wvpdE43VFtJq+lUDYDBFUwV8TZbuGXLV4D6wKafg13ldznKsyEvatubnmUe31zcvelSzOHF+XbaT+Bl9ObDg=="
    },
    "es6-promisify": {
      "version": "5.0.0",
      "resolved": "https://registry.npmjs.org/es6-promisify/-/es6-promisify-5.0.0.tgz",
      "integrity": "sha1-UQnWLz5W6pZ8S2NQWu8IKRyKUgM=",
      "requires": {
        "es6-promise": "^4.0.3"
      }
    },
    "extract-zip": {
      "version": "1.6.7",
      "resolved": "https://registry.npmjs.org/extract-zip/-/extract-zip-1.6.7.tgz",
      "integrity": "sha1-qEC0uK9kAyZMjbV/Txp0Mz74H+k=",
      "requires": {
        "concat-stream": "1.6.2",
        "debug": "2.6.9",
        "mkdirp": "0.5.1",
        "yauzl": "2.4.1"
      },
      "dependencies": {
        "debug": {
          "version": "2.6.9",
          "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
          "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
          "requires": {
            "ms": "2.0.0"
          }
        },
        "ms": {
          "version": "2.0.0",
          "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
          "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
        }
      }
    },
    "fd-slicer": {
      "version": "1.0.1",
      "resolved": "https://registry.npmjs.org/fd-slicer/-/fd-slicer-1.0.1.tgz",
      "integrity": "sha1-i1vL2ewyfFBBv5qwI/1nUPEXfmU=",
      "requires": {
        "pend": "~1.2.0"
      }
    },
    "fs.realpath": {
      "version": "1.0.0",
      "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
      "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8="
    },
    "glob": {
      "version": "7.1.3",
      "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.3.tgz",
      "integrity": "sha512-vcfuiIxogLV4DlGBHIUOwI0IbrJ8HWPc4MU7HzviGeNho/UJDfi6B5p3sHeWIQ0KGIU0Jpxi5ZHxemQfLkkAwQ==",
      "requires": {
        "fs.realpath": "^1.0.0",
        "inflight": "^1.0.4",
        "inherits": "2",
        "minimatch": "^3.0.4",
        "once": "^1.3.0",
        "path-is-absolute": "^1.0.0"
      }
    },
    "https-proxy-agent": {
      "version": "2.2.1",
      "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-2.2.1.tgz",
      "integrity": "sha512-HPCTS1LW51bcyMYbxUIOO4HEOlQ1/1qRaFWcyxvwaqUS9TY88aoEuHUY33kuAh1YhVVaDQhLZsnPd+XNARWZlQ==",
      "requires": {
        "agent-base": "^4.1.0",
        "debug": "^3.1.0"
      }
    },
    "inflight": {
      "version": "1.0.6",
      "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
      "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=",
      "requires": {
        "once": "^1.3.0",
        "wrappy": "1"
      }
    },
    "inherits": {
      "version": "2.0.3",
      "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
      "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4="
    },
    "isarray": {
      "version": "1.0.0",
      "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
      "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE="
    },
    "lodash.clonedeep": {
      "version": "4.5.0",
      "resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz",
      "integrity": "sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8="
    },
    "mime": {
      "version": "2.3.1",
      "resolved": "https://registry.npmjs.org/mime/-/mime-2.3.1.tgz",
      "integrity": "sha512-OEUllcVoydBHGN1z84yfQDimn58pZNNNXgZlHXSboxMlFvgI6MXSWpWKpFRra7H1HxpVhHTkrghfRW49k6yjeg=="
    },
    "minimatch": {
      "version": "3.0.4",
      "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
      "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
      "requires": {
        "brace-expansion": "^1.1.7"
      }
    },
    "minimist": {
      "version": "0.0.8",
      "resolved": "http://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz",
      "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0="
    },
    "mkdirp": {
      "version": "0.5.1",
      "resolved": "http://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz",
      "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=",
      "requires": {
        "minimist": "0.0.8"
      }
    },
    "ms": {
      "version": "2.1.1",
      "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz",
      "integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg=="
    },
    "once": {
      "version": "1.4.0",
      "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
      "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
      "requires": {
        "wrappy": "1"
      }
    },
    "path-is-absolute": {
      "version": "1.0.1",
      "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
      "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18="
    },
    "pend": {
      "version": "1.2.0",
      "resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz",
      "integrity": "sha1-elfrVQpng/kRUzH89GY9XI4AelA="
    },
    "process-nextick-args": {
      "version": "2.0.0",
      "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.0.tgz",
      "integrity": "sha512-MtEC1TqN0EU5nephaJ4rAtThHtC86dNN9qCuEhtshvpVBkAW5ZO7BASN9REnF9eoXGcRub+pFuKEpOHE+HbEMw=="
    },
    "progress": {
      "version": "2.0.0",
      "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.0.tgz",
      "integrity": "sha1-ihvjZr+Pwj2yvSPxDG/pILQ4nR8="
    },
    "proxy-from-env": {
      "version": "1.0.0",
      "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.0.0.tgz",
      "integrity": "sha1-M8UDmPcOp+uW0h97gXYwpVeRx+4="
    },
    "puppeteer": {
      "version": "1.8.0",
      "resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-1.8.0.tgz",
      "integrity": "sha512-wJ7Fxs03l4dy/ZXQACUKBBobIuJaS4NHq44q7/QinpAXFMwJMJFEIPjzoksVzUhZxQe+RXnjXH69mg13yMh0BA==",
      "requires": {
        "debug": "^3.1.0",
        "extract-zip": "^1.6.6",
        "https-proxy-agent": "^2.2.1",
        "mime": "^2.0.3",
        "progress": "^2.0.0",
        "proxy-from-env": "^1.0.0",
        "rimraf": "^2.6.1",
        "ws": "^5.1.1"
      }
    },
    "readable-stream": {
      "version": "2.3.6",
      "resolved": "http://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz",
      "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==",
      "requires": {
        "core-util-is": "~1.0.0",
        "inherits": "~2.0.3",
        "isarray": "~1.0.0",
        "process-nextick-args": "~2.0.0",
        "safe-buffer": "~5.1.1",
        "string_decoder": "~1.1.1",
        "util-deprecate": "~1.0.1"
      }
    },
    "rimraf": {
      "version": "2.6.2",
      "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.2.tgz",
      "integrity": "sha512-lreewLK/BlghmxtfH36YYVg1i8IAce4TI7oao75I1g245+6BctqTVQiBP3YUJ9C6DQOXJmkYR9X9fCLtCOJc5w==",
      "requires": {
        "glob": "^7.0.5"
      }
    },
    "safe-buffer": {
      "version": "5.1.2",
      "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
      "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="
    },
    "string_decoder": {
      "version": "1.1.1",
      "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
      "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==",
      "requires": {
        "safe-buffer": "~5.1.0"
      }
    },
    "typedarray": {
      "version": "0.0.6",
      "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz",
      "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c="
    },
    "underscore": {
      "version": "1.9.1",
      "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.9.1.tgz",
      "integrity": "sha512-5/4etnCkd9c8gwgowi5/om/mYO5ajCaOgdzj/oW+0eQV9WxKBDZw5+ycmKmeaTXjInS/W0BzpGLo2xR2aBwZdg=="
    },
    "underscore-keypath": {
      "version": "0.0.22",
      "resolved": "https://registry.npmjs.org/underscore-keypath/-/underscore-keypath-0.0.22.tgz",
      "integrity": "sha1-SKUoOSu278QkvhyqVtpLX6zPJk0=",
      "requires": {
        "underscore": "*"
      }
    },
    "user-agents": {
      "version": "1.0.28",
      "resolved": "https://registry.npmjs.org/user-agents/-/user-agents-1.0.28.tgz",
      "integrity": "sha512-g9I42OhFzs3Yh+M9TMwCrMW7znbNKBhhoFWGBLuj/JoAUH4Che3UnH/Yn+X/08aD9WAJyg7LtED7GqQcYNr1/A==",
      "requires": {
        "dot-json": "^1.0.4",
        "lodash.clonedeep": "^4.5.0"
      }
    },
    "util-deprecate": {
      "version": "1.0.2",
      "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
      "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8="
    },
    "wrappy": {
      "version": "1.0.2",
      "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
      "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
    },
    "ws": {
      "version": "5.2.2",
      "resolved": "https://registry.npmjs.org/ws/-/ws-5.2.2.tgz",
      "integrity": "sha512-jaHFD6PFv6UgoIVda6qZllptQsMlDEJkTQcybzzXDYM1XO9Y8em691FGMPmM46WGyLU4z9KMgQN+qrux/nhlHA==",
      "requires": {
        "async-limiter": "~1.0.0"
      }
    },
    "yauzl": {
      "version": "2.4.1",
      "resolved": "https://registry.npmjs.org/yauzl/-/yauzl-2.4.1.tgz",
      "integrity": "sha1-lSj0QtqxsihOWLQ3m7GU4i4MQAU=",
      "requires": {
        "fd-slicer": "~1.0.1"
      }
    }
  }
}

Not work require().default

I use typescript and get this error:

const userAgent = new user_agents_1.default();
                  ^
TypeError: user_agents_1.default is not a constructor
    at Object.<anonymous> (C:\Users\user\Desktop\new\sdfsdf.js:4:19)
    at Module._compile (internal/modules/cjs/loader.js:759:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:770:10)
    at Module.load (internal/modules/cjs/loader.js:628:32)
    at Function.Module._load (internal/modules/cjs/loader.js:555:12)
    at Function.Module.runMain (internal/modules/cjs/loader.js:822:10)
    at internal/main/run_main_module.js:17:11

code before compilation:

import UserAgent from 'user-agents';

const userAgent = new UserAgent();
console.log(userAgent.toString()); //
console.log(JSON.stringify(userAgent.data, null, 2));

code after compilation typescript:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const user_agents_1 = require("user-agents");
const userAgent = new user_agents_1.default();
console.log(userAgent.toString()); //
console.log(JSON.stringify(userAgent.data, null, 2));

I think it has something to do with: babel/babel#2212

I think this can be fixed using the plugin https://www.npmjs.com/package/babel-plugin-add-module-exports with a parameter addDefaultProperty

Uncaught ReferenceError: global is not defined

vite+vue3

universalModuleDefinition:10         
       Uncaught ReferenceError: global is not defined
    at node_modules/user-agents/dist/index.js (universalModuleDefinition:10:4)
    at __require2 (chunk-HYZYPRER.js?v=756193e6:15:50)
    at startup:4:28

Go version

Hi,

Do you know if your library replicated in GO?

If No, I was wondering if you'd accept to have your library replicated in GO?
I can do it if you want as I would very much like to have your intoli/user-agents library available in a GO environment.

Have a great day,

Extra quotes in userAgent strings

I've implemented a ruby library that uses the user-agents.json.gz and found that sometimes there is an extra quote(s) in userAgent, like this:
"userAgent": "\"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36",
or this:
"userAgent": "\"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36\"",

Old user agents supplied

I'm having issues with latest version of your package.
The following snippet gives me Chrome version that are <80

const ua = new UserAgent({ deviceCategory: "desktop" })
const userAgents = Array(100).fill().map(() => ua().toString())

I tried with ua(/Chrome\/83/) to get the newest version, but the filter won't apply. Any help?

Thanks

tablet is not detect

I using user-agents but his not detect tablet device. I am testing with toggle device toolbar in chrome/
I get this object and detecting desktop.

appName: "Netscape"
connection: {downlink: 6.7, effectiveType: "4g", rtt: 200}
deviceCategory: "desktop"
platform: "Win32"
pluginsLength: 3
screenHeight: 768
screenWidth: 1366
userAgent: "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36"
vendor: "Google Inc."
viewportHeight: 630
viewportWidth: 1350
weight: 0.00016750821718497432

Does the library give "sec-ch-ua*" headers?

My chrome (windows desktop) sends these headers related to user-agent / device identification:

sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="90", "Google Chrome";v="90"
sec-ch-ua-mobile: ?0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36

Obviously this pkg provides User-Agent, but does it give things like sec-ch-ua*? It'd be pretty cool if it did, closer to a real world browser that way.

cannot use in browser extension environment

when i used user-agents in browser extension environment (manifest v3,execute in background worker):
const userAgent = new UserAgent({deviceCategory: ‘desktop’}).data
i got a error like this :
Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'self' 'wasm-unsafe-eval' 'inline-speculation-rules' http://localhost:* http://127.0.0.1:*".
It looks related to browser content_security_policy ,and chrome does not support to set ‘unsafe-eval’ in extension manifest.json file。
as mentioned above,this library cannot be used in the browser extension environment

Error: No user agents matched your filters.

 const filter = {
    deviceCategory: 'mobile',
    platform: 'Android'
  };

this filter is returning error

Error: No user agents matched your filters.

why i can't specify android phones?

How to get the first 500 most-common user agents

Hi,

I do this userAgent = new UserAgents({ deviceCategory: 'desktop', userAgent: /^Mozilla/ }); to get Mozilla user agent on desktop device.

I want to get the first 500 most-common/recent Mozilla user agent on desktop device.
To do that I probably need to do the filtering using the custom function.

I don't know how to filter to get the first 500 most-common/recent Mozilla user agent on desktop device.

Can you help me?

You have been running npm publish with a polluted package.json, probably

In this repo dot-json is not a dependency.

But on npmjs it is listed as such:
image

If you install user-agents with npm install user-agents you will see inside its package.json that dot-json is present.

I would guess that whoever is running npm publish (probably it is run from circle-ci, as far as I can tell) has dot-json as a dependency. This means it is pushed to all users and downloaded when the package is used. (This isn't in itself so bad, but dot-json depends on a lib that pollutes the underscore package, which is potentially more problematic.)

The fix is installing dot-json with npm install dot-json --no-save in your circle-ci script.

(This might be because the default behavior of npm changed with npm@5 to imply --save.)

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.