npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

unique-random-useragent

v2.0.0

Published

Random user-agent generator with guaranteed uniqueness across restarts

Readme

Unique Random User-Agent Generator

A random user-agent generator that guarantees no repetition across restarts without using persistent storage. Works with npm, pnpm, yarn, and bun. Supports both ES modules (import) and CommonJS (const/require).

Features

  • Lifetime Uniqueness: Each user-agent is guaranteed to be unique, even across process restarts
  • No Persistent Storage: Works on serverless platforms like Render where files aren't persisted
  • Universal Compatibility: Supports npm, pnpm, yarn, and bun
  • Dual Module System: Works with both import and const/require
  • Desktop & Mobile: Generates both desktop and mobile user-agents
  • Realistic Agents: Uses real browser versions and OS combinations

How It Works

The generator creates truly random user-agents by:

  • Randomizing browser versions (Chrome 90-125, Firefox 100-122, Safari 14-17, Edge 90-120)
  • Randomizing OS versions (Windows 6-10, macOS 10-14, Linux distros, Android 8-14, iOS 13-17)
  • Randomizing WebKit versions (537-605)
  • Randomizing mobile device models (Samsung, Google Pixel, Xiaomi, Oppo, Huawei)
  • Using cryptographic random bytes for all selections
  • Tracking generated agents in memory to prevent duplicates within the same session

With billions of possible combinations, collision is virtually impossible. Each restart creates a new unique session, ensuring lifetime uniqueness without persistent storage.

Installation

# npm
npm install unique-random-useragent@latest

# pnpm
pnpm add unique-random-useragent@latest

# yarn
yarn add unique-random-useragent@latest

# bun
bun add unique-random-useragent@latest

Usage

ES Modules (import)

import getRandomUserAgent, { multipleUserAgents } from 'unique-random-useragent';

// Get a single random user-agent
const userAgent = getRandomUserAgent();

// Get a mobile user-agent
const mobileAgent = getRandomUserAgent({ mobile: true });

// Get multiple unique user-agents
const agents = multipleUserAgents(10);

CommonJS (require)

const getRandomUserAgent = require('unique-random-useragent');

// Get a single random user-agent
const userAgent = getRandomUserAgent();

// Get a mobile user-agent
const mobileAgent = getRandomUserAgent({ mobile: true });

// Multiple user-agents
const { multipleUserAgents } = require('unique-random-useragent');
const agents = multipleUserAgents(10);

API

getRandomUserAgent(options?)

Returns a single random user-agent string.

Options:

  • mobile (boolean): If true, returns only mobile user-agents. Default: false (mixed).

multipleUserAgents(count, options?)

Returns an array of unique random user-agent strings.

Parameters:

  • count (number): Number of user-agents to generate. Default: 10.
  • options (object): Same as getRandomUserAgent options.

Testing

# Test ES modules
node test.js

# Test CommonJS
node test.cjs

Example User-Agents

Desktop:

Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.6099 Safari/537.36
Mozilla/5.0 (Macintosh; Intel Mac OS X 14_1) Gecko/20100101 Firefox/121.0

Mobile:

Mozilla/5.0 (Linux; Android 14; SM-S918B) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.6099 Mobile Safari/537.36
Mozilla/5.0 (iPhone; CPU iPhone OS 17_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Mobile/15E148 Safari/604.1

Deployment

This package is designed to work on serverless platforms where:

  • Files cannot be persisted between deployments
  • Process restarts happen frequently
  • No database or cache is available

Perfect for platforms like Render, Vercel, Netlify, AWS Lambda, etc.

License

MIT