faky-useragent
v1.0.0
Published
A fast Node.js library that provides randomized, up-to-date user-agent strings from a real-world database. This is a Node.js port of the `fake-useragent` Python library. It loads ~10,000 JSON user agents into memory instantly.
Readme
faky-useragent
A fast Node.js library that provides randomized, up-to-date user-agent strings from a real-world database.
This is a Node.js port of the fake-useragent Python library. It loads ~10,000 JSON user agents into memory instantly.
Installation
npm install faky-useragentBasic Usage
Just require the module and instantiate the class. Data is loaded synchronously upon require.
const UserAgent = require('faky-useragent');
// Initialize with default filters
const ua = new UserAgent();
// Get a random user-agent string
console.log(ua.random);
// Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36
// Get an agent string from a specific browser
console.log(ua.chrome);
console.log(ua.firefox);
console.log(ua.safari);
console.log(ua.edge);
console.log(ua.get('Samsung Internet')); // Dynamic lookup
// Get the full metadata dictionary (JSON object) instead of the string
console.log(ua.getChrome);
/*
{
useragent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36...',
percent: 1.25,
type: 'desktop',
browser: 'Chrome',
browser_version: '127.0.0.0',
...
}
*/Advanced Filtering
You can strict-filter the database based on the devices, OS, browsers, and usage metrics you want.
The filters seamlessly match the Python fake-useragent library syntax.
const strictUa = new UserAgent({
browsers: ['Edge', 'Chrome'], // Only return these browsers
os: 'Linux', // Only return Linux agents
platforms: ['mobile'], // Only return mobile devices
minVersion: 120.0, // Only version >= 120
minPercentage: 0.1 // Only agents that hold >= 0.1% market share
});
console.log(strictUa.random);