Registry / http-networking / useragent

useragent

JSON →
library0.1.1jsnpmunverified

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.

npm install useragent
INSTALL
IMPORT
SIG · USERAGENT
U
useragent
http-networkingjavascriptv0.1.1
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

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

useragent
✓ const useragent = require('useragent');
✗ import useragent from 'useragent';
This package is CommonJS-only. Direct ESM import will fail without a compatibility layer.
useragent.parse
✓ const agent = useragent.parse(userAgentString);
✗ const { parse } = require('useragent');
The primary parsing function is a method of the default export, not a named export itself.
Agent
✓ const agent = useragent.parse(userAgentString); console.log(agent.toAgent());
✗ import { Agent } from 'useragent';
The `Agent` instance is returned by `useragent.parse` and is not directly exported for import.

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 issues
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.
fix
Migrate to a actively maintained and up-to-date user agent parsing library (e.g., 'ua-parser-js', 'platform').
affects: >=2.3.0
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.
fix
Ensure your project is configured for CommonJS or use a bundler that transpiles CommonJS modules for ESM environments. Alternatively, choose a modern library that supports ESM natively.
affects: >=2.0.0
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.
fix
Avoid using the `useragent(true)` feature. If you must use this library, rely solely on its bundled, albeit outdated, definitions. Preferably, migrate to a modern, actively maintained user agent parser.
affects: >=2.0.0
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.
fix
Benchmark against current alternatives if performance is critical for modern user agents; however, the primary issue remains the outdated parsing database.
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: require is not a function
Attempting to `require('useragent')` in an ECMAScript Module (ESM) file without proper transpilation or bundling.
fix
Ensure your file is a CommonJS module (e.g., by using `.js` extension with `"type": "commonjs"` in `package.json` or by not setting `"type": "module"`). If using ESM, you might need to use `import * as useragent from 'useragent';` or a build tool to handle CJS imports.
Error: Cannot find module 'yamlparser'
The `useragent(true)` function was called to fetch and compile live user agent definitions, but the optional `yamlparser` dependency was not installed.
fix
To use the live update feature, you must explicitly install `yamlparser` and `request` via `npm install yamlparser request --save`. However, this is strongly discouraged due to the age and known vulnerabilities of these dependencies.
Incorrectly parsed or unrecognized user agent string for a modern browser/OS.
The package's user agent definition database is 8 years old and does not contain rules for recent browsers, operating systems, or device patterns.
fix
This issue cannot be fixed within this library. You must switch to a different, actively maintained user agent parsing library that receives regular updates.
Upgrade
Version history
0.1.1latest on npm
Audit
Dependencies
yamlparseroptionalRequired if `useragent(true)` is called to fetch and compile live user agent definitions.
requestoptionalRequired if `useragent(true)` is called to fetch live user agent definitions from a remote server.
Agent activity
19 hits · last 30 days
node
16
Amazon
1
OpenAI (training)
1
Resources
useragent — npm install useragent · libregistry