ua-parser-js
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
UA-Parser-JS is a practical Javascript library that identifies the browser, engine, operating system, CPU, and device type/model by parsing the user-agent data. This library supports both browser and node.js environment, providing detailed user context that can be essential in various use-cases, like tracking how users interact with web content, developing responsive UI, or for statistical purposes. Robust tracing of this information helps in enhancing the performance and user experience on your website or application.
To use the UA-Parser-JS, at first, you need to install it through the npm package manager, by running the command npm install ua-parser-js
. In node.js environment, the basic usage would look something like this:
var parser = require('ua-parser-js');
var ua = parser('User-Agent string goes here');
console.log(ua.browser); // Outputs the browser info from user-agent string
In the browser, you can include the ua-parser.min.js in your html file and use it like so:
<script src="ua-parser.min.js"></script>
<script>
var parser = new UAParser();
var result = parser.getResult();
console.log(result.browser); // Output: Browser's name and version
</script>
Noteworthy methods provided by the library include getResult()
, getBrowser()
, getDevice()
, getEngine()
, getOS()
, getCPU()
, getUA()
, and setUA(user-agent)
.
The documentation for UA-Parser-JS helps in understanding the usage and helps in accessing the desired information. There are two versions available and can be accessed at the following links:
For customized usage, the documentation provides in-depth explanation on creating extensions as well. Multiple demos and examples are also provided in the documentation to ensure an easy understanding of the library's functionality.