Skip to content

manzil-infinity180/random-user-agent

Repository files navigation

Random User Agents

npm version

Github

Description

A simple yet powerful NPM package to generate random user agents effortlessly. Whether you're working on web scraping, testing, or automation, this tool provides flexibility to create one or many user agents in seconds.


Features

  • Generate single or multiple user agents.
  • Built with TypeScript for type safety and maintainability.
  • Tested with Vitest and formatted with Prettier for consistent code quality.
  • Fully automated CI/CD pipeline via GitHub Actions.
  • Generate user agent - Chrome, Firefox, Edge, Android
  • Customize Your User Agent and filter out which browser you want
  • All in one Random User Agent generateUserAgentRandom

Use this package with Puppeteer

pupeeter-result-image

Getting Started

Installation is done using the npm install command:

npm i @rahulxf/random-user-agent
import { generateUserAgents } from '@rahulxf/random-user-agent';

// Generate 5 user agents
const value = generateUserAgents(5);
console.log(value);

Result

[
  'Mozilla/5.0 (Macintosh; Intel Mac OS X 14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.350.56 Safari/537.36',
  'Mozilla/5.0 (Macintosh; Intel Mac OS X 14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.344.67 Safari/537.36',
  'Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.259.94 Safari/537.36',
  'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.434.38 Safari/537.36',
  'Mozilla/5.0 (Macintosh; Intel Mac OS X 14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.123.89 Safari/537.36'
]

result-image

Other Example

Here is implementation of each and every things

Function Description
generateAndroidAgents Generate android agents(>1), max_count is required field
generateEdgeAgents Generate edge agents(>1), max_count is required field
generateFirefoxAgents Generate firefox agents(>1), max_count is required field
generateUserAgentOnType Generate user agent based on types(firefox, chrome, edge, android).
getAndroidAgent get one android agent
getEdgeAgent get one edge agent
getFirefoxAgent get one firefox agent
getUserAgent get one chrome agent
generateUserAgentRandom generate random user agent include each types

Example

console.log({
  generateAndroidAgents: generateAndroidAgents(10),
  generateEdgeAgents: generateEdgeAgents(10),
  generateFirefoxAgents: generateFirefoxAgents(10),
  'generateUserAgentOnType:Firefox': generateUserAgentOnType({
    options: {
      type: 'firefox',
    },
  }),
  'generateUserAgentOnType:Chrome': generateUserAgentOnType({
    options: {
      type: 'chrome',
    },
  }),
  'generateUserAgentOnType:Android': generateUserAgentOnType({
    options: {
      type: 'android',
    },
  }),
  'generateUserAgentOnType:edge': generateUserAgentOnType({
    options: {
      type: 'edge',
    },
  }),
  getAndroidAgent: getAndroidAgent(),
  getEdgeAgent: getEdgeAgent(),
  getFirefoxAgent: getFirefoxAgent(),
  generateUserAgents: generateUserAgents(10),
  getUserAgent: getUserAgent(),
  generateUserAgentRandom: generateUserAgentRandom(),
});

Result

{
  generateAndroidAgents: [
    'Mozilla/5.0 (Linux; Android 12; moto g pure) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Mobile Safari/537.36',
    'Mozilla/5.0 (Linux; Android 12; moto g stylus 5G) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Mobile Safari/537.36',
    'Mozilla/5.0 (Linux; Android 12; moto g power (2022)) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Mobile Safari/537.36',
    ... more items
  ],

  generateEdgeAgents: [
    'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.457.29 Safari/537.36 Edg/114.457.29',
    'Mozilla/5.0 (X11; Ubuntu i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.427.17 Safari/537.36 Edg/111.427.17',
    'Mozilla/5.0 (Windows NT 11.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.303.22 Safari/537.36 Edg/115.303.22',
    ... more items
  ],

  generateFirefoxAgents: [
    'Mozilla/5.0 (X11; Linux x86_64; rv:110.0) Gecko/20100101 Firefox/110.0',
    'Mozilla/5.0 (X11; Linux x86_64; rv:121.0) Gecko/20100101 Firefox/121.0',
    'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/109.0',
    'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0',
    ... more items
  ],

  'generateUserAgentOnType:Firefox': 'Mozilla/5.0 (Windows NT 11.0; Win64; x64; rv:106.0) Gecko/20100101 Firefox/106.0',
  'generateUserAgentOnType:Chrome': 'Mozilla/5.0 (X11; Fedora i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.374.92 Safari/537.36',
  'generateUserAgentOnType:Android': 'Mozilla/5.0 (Linux; Android 13; SM-A536B) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Mobile Safari/537.36',
  'generateUserAgentOnType:edge': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.216.30 Safari/537.36 Edg/114.216.30',
  getAndroidAgent: 'Mozilla/5.0 (Linux; Android 13; Pixel 6 Pro) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Mobile Safari/537.36',
  getEdgeAgent: 'Mozilla/5.0 (X11; Ubuntu i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.362.48 Safari/537.36 Edg/111.362.48',
  getFirefoxAgent: 'Mozilla/5.0 (X11; Linux x86_64; rv:115.0) Gecko/20100101 Firefox/115.0',

  generateUserAgents: [
    'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.52 Safari/537.36',
    'Mozilla/5.0 (Macintosh; Intel Mac OS X 13_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.485.20 Safari/537.36',
    'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.355.31 Safari/537.36',
    ... more items
  ],

  getUserAgent: 'Mozilla/5.0 (X11; Ubuntu i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.79.79 Safari/537.36',

  generateUserAgentRandom: [
    'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:113.0) Gecko/20100101 Firefox/113.0',
    'Mozilla/5.0 (X11; Linux x86_64; rv:103.0) Gecko/20100101 Firefox/103.0',
    'Mozilla/5.0 (Macintosh; Intel Mac OS X 14.7; rv:123.0) Gecko/20100101 Firefox/123.0',
    'Mozilla/5.0 (Macintosh; Intel Mac OS X 14.7; rv:119.0) Gecko/20100101 Firefox/119.0',
    'Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:130.0) Gecko/20100101 Firefox/130.0',
    'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/109.0',
    'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:120.0) Gecko/20100101 Firefox/120.0',
    'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:130.0) Gecko/20100101 Firefox/130.0',
    ... 9992 more items
  ]
}

Generate a single user agent:

  • getUserAgent() method
import { getUserAgent } from '@rahulxf/random-user-agent';

console.log(getUserAgent());

// 'Mozilla/5.0 (Macintosh; Intel Mac OS X 14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.123.89 Safari/537.36'

// You can also specify the count (optional)
console.log(getUserAgent(10));

Development & Contribution

If you'd like to contribute or run the project locally:

  1. Clone the repository:

    git clone https://github.com/manzil-infinity180/random-user-agent.git
    cd random-user-agent
    npm install
  2. Run tests:

    npm run test
  3. Ensure changes meet the project's standards:

    npm run ci

This project uses TypeScript for development, Vitest for testing, and Prettier for formatting. All contributions are welcome!


Technology Stack

  • Languages & Tools: TypeScript, JavaScript, Node.js
  • Testing: Vitest
  • Code Formatting: Prettier
  • Automation: GitHub Actions

Package Details

Here's an overview of the key NPM scripts included:

Script Description
build Compiles TypeScript files to JavaScript.
ci Runs all checks (build, format, exports, tests).
format Formats code using Prettier.
test Runs tests using Vitest.
local-release Handles changeset versioning and local publishing.

License

This project is licensed under the MIT License, allowing developers to use, modify, and share freely.

About

npm package to generate random user agent | will help you while scraping data

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published