Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
user-agents
Advanced tools
The 'user-agents' npm package is designed to generate random user-agent strings that can be used for web scraping, testing, or any other scenario where you need to simulate different browsers and devices.
Generate a random user-agent
This feature allows you to generate a random user-agent string. The generated user-agent string can be used to simulate different browsers and devices.
const UserAgent = require('user-agents');
const userAgent = new UserAgent();
console.log(userAgent.toString());
Generate a user-agent with specific options
This feature allows you to generate a user-agent string with specific options, such as targeting mobile devices. This can be useful for testing how your application behaves on different types of devices.
const UserAgent = require('user-agents');
const userAgent = new UserAgent({ deviceCategory: 'mobile' });
console.log(userAgent.toString());
Access user-agent properties
This feature allows you to access detailed properties of the generated user-agent, such as browser name, version, platform, and more. This can be useful for logging or debugging purposes.
const UserAgent = require('user-agents');
const userAgent = new UserAgent();
console.log(userAgent.data);
The 'random-useragent' package also generates random user-agent strings. It provides a simpler API compared to 'user-agents' and is easier to use for basic use cases. However, it lacks the advanced customization options available in 'user-agents'.
The 'useragent' package is primarily focused on parsing and identifying user-agent strings rather than generating them. It can be used to analyze user-agent strings and extract information about the browser, version, and platform. It complements 'user-agents' by providing analysis capabilities.
The 'ua-parser-js' package is a JavaScript library for parsing user-agent strings and extracting detailed information about the browser, engine, OS, CPU, and device. While it does not generate user-agent strings, it is useful for analyzing and understanding user-agent data.
User Agents is a JavaScript module for generating random user agents according to how frequently they're used in the wild. This is useful for web scraping because it's often desired to create realistic traffic patterns. There are several other similar projects for generating random user agents, but User Agents is the only one that automatically publishes new versions with updated data on a regular basis. This ensures that your user agents will always be realistic and up to date.
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
The userAgents.random()
method can be used to generate a random user agent.
The most common user agents are weighted with higher probabilities so that the randomly generated user agents will follow realistic probability distributions.
For example, the following code snippet will generate five random user agents based on these probabilities.
// Import the User Agents package.
const userAgents = require('user-agents');
// Log out five random user agents.
for (let i = 0; i < 5; i++) {
const userAgent = userAgents.random();
console.log(userAgents);
};
The output will be random, and will also depend on which package version you're using, but a typical output would look something like this.
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:61.0) Gecko/20100101 Firefox/61.0
Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1.2 Safari/605.1.15
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36
The user agent frequency data used in this library is currently provided by the Will's House Tech Blog.
Contributions are welcome, but please follow these contributor guidelines outlined in CONTRIBUTING.md.
Slice is licensed under a BSD 2-Clause License and is copyright Intoli, LLC.
FAQs
A JavaScript library for generating random user agents.
We found that user-agents demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.