UAParser.js is a comprehensive JavaScript library designed for detecting detailed information about a user's browser, operating system, CPU architecture, and device type/model. It leverages both traditional User-Agent strings and modern Client Hints data for accurate analysis. The current stable version is 2.0.9, with frequent patch releases indicating active development and continuous updates to its detection database for new browsers, OSes, and devices. This library is distinguished by its robust support for both client-side (browser) and server-side (Node.js) environments, offering a unified API. Key differentiators include its detailed detection capabilities, compact size, and up-to-date definitions, including specific submodules for bot and crawler detection, as well as features for chaining `withClientHints()` and `withFeatureCheck()`. A critical aspect for users is the change in licensing: while version 1.x was released under the permissive MIT License, version 2.x and onwards are distributed under the AGPL-3.0 License, which has significant implications for commercial and open-source projects.
npm install ua-parser-jsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates parsing a user-agent string, utilizing client hints for richer detection (relevant in server-side Node.js applications), and using a utility function from the 'extensions' submodule to check for bots. It highlights the primary API for both traditional and modern detection methods.
Review your project's licensing model. If AGPL-3.0 is incompatible, consider remaining on version 1.x (which is MIT licensed) or exploring alternative libraries. Consult legal counsel for specific compliance advice.
Before upgrading, carefully read the `CHANGELOG.md` file and the official version 2.x documentation at `https://docs.uaparser.dev` to understand all breaking changes and adjust your code accordingly.
Ensure your server-side application is configured to receive and forward Client Hint headers (e.g., `Sec-CH-UA`, `Sec-CH-UA-Platform`, etc.) from incoming requests to the `withClientHints()` method. In Node.js, this typically involves converting `http.IncomingHttpHeaders` to a `Headers` object.
For client-side detection, always test thoroughly across different browsers and extensions. For more reliable and comprehensive detection, especially with Client Hints, consider performing parsing on the server-side where the raw HTTP headers are available and less prone to client-side manipulation.
For ESM, use `import UAParser from 'ua-parser-js';`. For CommonJS, use `const UAParser = require('ua-parser-js');`.Ensure you call `const parser = new UAParser(userAgentString);` with a string (or let it default to `navigator.userAgent` in browser) and then `const result = parser.getResult();` before trying to access `result.browser`, `result.os`, etc.
Verify the exact import path for the submodule (e.g., `ua-parser-js/extensions/bot-detection`). Ensure TypeScript is configured correctly to resolve module paths and that `ua-parser-js` is installed with its types, which are shipped with the package.
No dependency data recorded yet.