unique-random-useragent
v2.0.0
Published
Random user-agent generator with guaranteed uniqueness across restarts
Maintainers
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
importandconst/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@latestUsage
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 asgetRandomUserAgentoptions.
Testing
# Test ES modules
node test.js
# Test CommonJS
node test.cjsExample 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.0Mobile:
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.1Deployment
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
