UAParser Class Overview
Constructor
new UAParser(uastring?: string, extensions?: UAParserExt, headers?: UAParserHeaders): UAParser
When called with the new
keyword, it will return a new instance of UAParser
.
UAParser(uastring?: string, extensions?: UAParserExt, headers?: UAParserHeaders): IResult`
When called without the new
keyword, it will directly return the results of getResult()
:
TIP
In BROWSER environment you don't need to pass the user-agent string, as it should automatically get the string from the current window.navigator.userAgent
.
Whereas in NODE.JS environment, user-agent string must be supplied, usually you can find it in: request.headers["user-agent"]
.
Code Example
Using new UAParser()
const parser = new UAParser("your user-agent here"); // you need to pass the user-agent for nodejs
console.log(parser);
/*
UAParser instance
*/
const result = parser.getResult();
console.log(result);
/*
{
ua : "",
browser : {},
engine : {},
os : {},
device : {},
cpu : {}
}
*/
Using UAParser()
const result = UAParser("your user-agent here");
console.log(result);
/*
{
ua : "",
browser : {},
engine : {},
os : {},
device : {},
cpu : {}
}
*/
Methods
The methods are self explanatory, here's a small overview of available methods:
returns the browser name, version, and major.
returns CPU architectural design name.
returns the device model, type, vendor.
returns the browser engine name and version.
returns the operating system name and version.
returns all function object calls, user-agent string, browser info, cpu, device, engine, os.
returns the user-agent string.
set a custom user-agent string to be parsed.