Registry / http-networking / useragent

useragent

JSON →
library2.3.0jsnpmunverified

The `useragent` package, currently at version 2.3.0, is an abandoned Node.js library designed for parsing user agent strings. It was developed to provide high accuracy by leveraging hand-tuned regular expressions derived from Browserscope's research, aiming to correctly identify browser names and versions where generic parsers might fail. The library differentiated itself through a benchmark-driven approach, claiming superior performance with a pre-compiled regular expression library and deferred parsing for OS and device information. It also offered an optional feature to fetch live, updated parsing rules from remote servers, requiring additional `yamlparser` and `request` dependencies. However, the package has not seen updates since its last publish 8 years ago, indicating it is no longer actively maintained and its user agent data is significantly out of date, making it unsuitable for modern applications.

http-networkingserialization
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

This package is CommonJS-only. Direct ESM import will fail without a compatibility layer.

const useragent = require('useragent');

The primary parsing function is a method of the default export, not a named export itself.

const agent = useragent.parse(userAgentString);

The `Agent` instance is returned by `useragent.parse` and is not directly exported for import.

const agent = useragent.parse(userAgentString); console.log(agent.toAgent());

Demonstrates basic usage of `useragent.parse()` with server-side and optional client-side user agent strings, and how to access parsed properties.

const useragent = require('useragent'); // Simulate a request header user agent string const serverUserAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36'; // Simulate an optional client-side JavaScript user agent string (e.g., from Chrome Frame detection) const clientUserAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 Chrome-Frame/90.0.4430.212'; // Parse only the server user agent const agent1 = useragent.parse(serverUserAgent); console.log('Agent 1 (server only):', agent1.toAgent()); console.log('OS 1:', agent1.os.toAgent()); // Parse both server and client user agents const agent2 = useragent.parse(serverUserAgent, clientUserAgent); console.log('Agent 2 (server + client):', agent2.toAgent()); console.log('OS 2:', agent2.os.toAgent()); // Attempt to update the database (requires 'yamlparser' and 'request' to be installed) // useragent(true); // Uncomment with caution, as dependencies are old and may have security issues /* Example Output: Agent 1 (server only): Chrome 123.0.0 OS 1: Mac OS X 10.15.7 Agent 2 (server + client): Chrome Frame 90.0.4430 OS 2: Windows 10 */
Debug
Known footguns
breakingThe `useragent` package is effectively abandoned, with its last update 8 years ago. This means its internal database of user agent parsing rules is severely outdated and will incorrectly parse or fail to recognize modern browsers, operating systems, and devices.
gotchaThis package is CommonJS-only (`require`). Attempting to use `import` syntax in an ESM module without a bundler or transpiler will result in a runtime error.
breakingThe optional feature to fetch live user agent definitions by calling `useragent(true)` relies on the `yamlparser` and `request` packages. Both of these are very old and unmaintained, with `request` being officially deprecated and having known security vulnerabilities. Using this feature introduces significant security risks and potential compatibility issues with newer Node.js versions.
gotchaThe accuracy claims are based on benchmarks from 8+ years ago against contemporary libraries. Modern alternatives have likely surpassed its performance and accuracy, especially concerning up-to-date user agent strings.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
0 hits · last 30 days

No traffic data recorded yet.

Resources