Constructor
new Parser(UA, skipParsingOrHintsopt, clientHintsopt)
Create instance of Parser
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
UA |
String | User-Agent string |
||
skipParsingOrHints |
Boolean | ClientHints |
<optional> |
false
|
Either a boolean to skip parsing, or a ClientHints object containing User-Agent Client Hints data |
clientHints |
ClientHints |
<optional> |
null
|
User-Agent Client Hints data (navigator.userAgentData) |
Methods
getBrandVersion(brandName) → {string|undefined}
Get brand version from Client Hints
Example
const parser = Bowser.getParser(UA, clientHints);
const version = parser.getBrandVersion('Google Chrome');
console.log(version); // '131'
Parameters:
| Name | Type | Description |
|---|---|---|
brandName |
string | The brand name to get version for |
Returns:
- Type
- string | undefined
getBrowser() → {Object}
Get parsed browser object
Returns:
- Type
- Object
getBrowserName() → {String}
Get browser's name
Returns:
Browser's name or an empty string
- Type
- String
getBrowserVersion() → {String}
Get browser's version
Returns:
version of browser
- Type
- String
getEngine() → {Object}
Get parsed engine
Returns:
- Type
- Object
getEngineName() → {String}
Get engines's name
Returns:
Engines's name or an empty string
- Type
- String
getHints() → {ClientHints|null}
Get Client Hints data
Example
const parser = Bowser.getParser(UA, clientHints);
const hints = parser.getHints();
console.log(hints.platform); // 'Windows'
console.log(hints.mobile); // false
Returns:
- Type
- ClientHints | null
getOS() → {Object}
Get OS
Example
this.getOS();
{
name: 'macOS',
version: '10.11.12'
}
Returns:
- Type
- Object
getOSName(toLowerCaseopt) → {String}
Get OS name
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
toLowerCase |
Boolean |
<optional> |
return lower-cased value |
Returns:
name of the OS — macOS, Windows, Linux, etc.
- Type
- String
getOSVersion() → {String}
Get OS version
Returns:
full version with dots ('10.11.12', '5.6', etc)
- Type
- String
getPlatform() → {Object}
Get parsed platform
Returns:
- Type
- Object
getPlatformType(toLowerCaseopt) → {*}
Get platform name
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
toLowerCase |
Boolean |
<optional> |
false
|
Returns:
- Type
- *
getResult() → {ParsedResult}
Get parsed result
Returns:
- Type
- ParsedResult
getUA() → {String}
Get UserAgent string of current Parser instance
Returns:
User-Agent String of the current
- Type
- String
hasBrand(brandName) → {boolean}
Check if a brand exists in Client Hints brands array
Example
const parser = Bowser.getParser(UA, clientHints);
if (parser.hasBrand('Google Chrome')) {
console.log('Chrome detected!');
}
Parameters:
| Name | Type | Description |
|---|---|---|
brandName |
string | The brand name to check for |
Returns:
- Type
- boolean
is(anything, includingAliasopt) → {Boolean}
Is anything? Check if the browser is called "anything", the OS called "anything" or the platform called "anything"
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
anything |
String | |||
includingAlias |
<optional> |
false
|
The flag showing whether alias will be included into comparison |
Returns:
- Type
- Boolean
isBrowser(browserName, includingAliasopt) → {boolean}
Check if the browser name equals the passed string
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
browserName |
string | The string to compare with the browser name |
||
includingAlias |
<optional> |
false
|
The flag showing whether alias will be included into comparison |
Returns:
- Type
- boolean
isEngine(engineName) → {boolean}
Check if the engine name equals the passed string
Parameters:
| Name | Type | Description |
|---|---|---|
engineName |
string | The string to compare with the engine name |
Returns:
- Type
- boolean
isOS(osName) → {boolean}
Check if the OS name equals the passed string
Parameters:
| Name | Type | Description |
|---|---|---|
osName |
string | The string to compare with the OS name |
Returns:
- Type
- boolean
isPlatform(platformType) → {boolean}
Check if the platform type equals the passed string
Parameters:
| Name | Type | Description |
|---|---|---|
platformType |
string | The string to compare with the platform type |
Returns:
- Type
- boolean
parse() → {Parser}
Parse full information about the browser
Returns:
- Type
- Parser
parseBrowser() → {Object}
Get parsed browser object
Returns:
- Type
- Object
parseEngine() → {Object}
Get parsed platform
Returns:
- Type
- Object
parseOS() → {*|Object}
Parse OS and save it to this.parsedResult.os
Returns:
- Type
- * | Object
parsePlatform() → {Object}
Get parsed platform
Returns:
- Type
- Object
satisfies(checkTree) → {Boolean|undefined}
Check if parsed browser matches certain conditions
Example
const browser = Bowser.getParser(window.navigator.userAgent);
if (browser.satisfies({chrome: '>118.01.1322' }))
// or with os
if (browser.satisfies({windows: { chrome: '>118.01.1322' } }))
// or with platforms
if (browser.satisfies({desktop: { chrome: '>118.01.1322' } }))
Parameters:
| Name | Type | Description |
|---|---|---|
checkTree |
Object | It's one or two layered object, which can include a platform or an OS on the first layer and should have browsers specs on the bottom-laying layer |
Returns:
Whether the browser satisfies the set conditions or not.
Returns undefined when the browser is no described in the checkTree object.
- Type
- Boolean | undefined
some(anythings) → {Boolean}
Check if any of the given values satisfies this.is(anything)
Parameters:
| Name | Type | Description |
|---|---|---|
anythings |
Array.<String> |
Returns:
- Type
- Boolean
test(regex) → {Boolean}
Test a UA string for a regexp
Parameters:
| Name | Type | Description |
|---|---|---|
regex |
RegExp |
Returns:
- Type
- Boolean