### Get OS Version Source: https://github.com/bowser-js/bowser/blob/master/docs/Parser.html Retrieves the full version string of the operating system, including dots (e.g., '10.11.12', '5.6'). ```javascript parser.getOSVersion() ``` -------------------------------- ### Full Browser and OS Parsing Source: https://github.com/bowser-js/bowser/blob/master/README.md Parse a User-Agent string to get detailed browser, OS, platform, and engine information. ```APIDOC ```javascript console.log(Bowser.parse(window.navigator.userAgent)); // outputs { browser: { name: "Internet Explorer" version: "11.0" }, os: { name: "Windows" version: "NT 6.3" versionName: "8.1" }, platform: { type: "desktop" }, engine: { name: "Trident" version: "7.0" } } ``` ``` -------------------------------- ### Create a Parser Instance with User-Agent and Client Hints Source: https://github.com/bowser-js/bowser/blob/master/docs/bowser.js.html This example shows how to create a Parser instance using both the User-Agent string and User-Agent Client Hints for more accurate detection. ```javascript const parser = Bowser.getParser( window.navigator.userAgent, window.navigator.userAgentData ); ``` -------------------------------- ### Parse User-Agent String with Client Hints Source: https://github.com/bowser-js/bowser/blob/master/docs/bowser.js.html This example demonstrates parsing a User-Agent string along with User-Agent Client Hints to obtain detailed browser information. ```javascript const result = Bowser.parse( window.navigator.userAgent, window.navigator.userAgentData ); ``` -------------------------------- ### Get Browser Version Source: https://github.com/bowser-js/bowser/blob/master/docs/parser.js.html Retrieves the version of the browser. ```javascript return this.getBrowser().version; ``` -------------------------------- ### Get Platform Type Source: https://github.com/bowser-js/bowser/blob/master/docs/parser.js.html Retrieves the type of the platform. Optionally returns the type in lowercase. ```javascript const { type } = this.getPlatform(); ``` -------------------------------- ### Get Platform Information Source: https://github.com/bowser-js/bowser/blob/master/docs/Parser.html Retrieves a parsed object containing detailed information about the user's platform. ```javascript parser.getPlatform() ``` -------------------------------- ### Working with Client Hints Source: https://github.com/bowser-js/bowser/blob/master/README.md Access and query Client Hints data using Bowser.js. This includes getting the full Client Hints object, checking for specific brands, and retrieving brand versions. ```APIDOC ## Working with Client Hints Bowser provides methods to access and query Client Hints data: ```javascript const browser = Bowser.getParser( window.navigator.userAgent, window.navigator.userAgentData ); // Get the full Client Hints object const hints = browser.getHints(); // Returns the ClientHints object or null if not provided // Check if a specific brand exists if (browser.hasBrand('Google Chrome')) { console.log('This is Chrome!'); } // Get the version of a specific brand const chromeVersion = browser.getBrandVersion('Google Chrome'); console.log(`Chrome version: ${chromeVersion}`); ``` The Client Hints object structure: ```javascript { brands: [ { brand: 'Google Chrome', version: '131' }, { brand: 'Chromium', version: '131' }, { brand: 'Not_A Brand', version: '24' } ], mobile: false, platform: 'Windows', platformVersion: '15.0.0', architecture: 'x86', model: '', wow64: false } ``` **Note:** Client Hints improve detection for browsers like DuckDuckGo and other Chromium-based browsers that may have similar User-Agent strings. When Client Hints are not provided, Bowser falls back to standard User-Agent string parsing. ``` -------------------------------- ### Basic Browser Parsing Source: https://github.com/bowser-js/bowser/blob/master/README.md Parse a User-Agent string to get basic browser information. ```APIDOC ```javascript const browser = Bowser.getParser(window.navigator.userAgent); console.log(browser.getBrowser()); // outputs { name: "Internet Explorer" version: "11.0" } ``` ``` -------------------------------- ### Get OS Name Source: https://github.com/bowser-js/bowser/blob/master/docs/Parser.html Retrieves the name of the operating system, such as macOS, Windows, or Linux. ```javascript parser.getOS() ``` -------------------------------- ### Get Browser Info with User-Agent Client Hints Source: https://github.com/bowser-js/bowser/blob/master/docs/index.html Pass User-Agent Client Hints data to Bowser for more accurate browser detection. This is the recommended approach for modern browsers. ```javascript const browser = Bowser.getParser( window.navigator.userAgent, window.navigator.userAgentData ); console.log(`The current browser name is "${browser.getBrowserName()}"`); ``` -------------------------------- ### Get OS Details with Bowser.js Source: https://context7.com/bowser-js/bowser/llms.txt Retrieve the parsed OS object, its name, or its version. The versionName field maps numeric versions to human-readable names. ```javascript const parser = Bowser.getParser( "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 " + "(KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36" ); console.log(parser.getOS()); // { name: "Windows", version: "NT 6.3", versionName: "8.1" } console.log(parser.getOSName()); // "Windows" console.log(parser.getOSName(true)); // "windows" (toLowerCase) console.log(parser.getOSVersion()); // "NT 6.3" // macOS example const macParser = Bowser.getParser( "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 " + "(KHTML, like Gecko) Chrome/100.0.0.0 Safari/537.36" ); console.log(macParser.getOS()); // { name: "macOS", version: "10.14.6", versionName: "Mojave" } ``` -------------------------------- ### Satisfies() Version DSL Examples Source: https://github.com/bowser-js/bowser/blob/master/AGENTS.md Demonstrates how to use the Parser.satisfies() method for conditional browser, OS, or platform checks. Supports version operators like '>', '>=', '<', '<=', '=', and '~' for loose prefix matching. ```javascript // Simple browser check parser.satisfies({ chrome: '>118', firefox: '~100' }) // Nested by OS or platform parser.satisfies({ windows: { chrome: '>118' } }, macos: { safari: '>=15' }) parser.satisfies({ desktop: { chrome: '>118' } }, mobile: { safari: '>=15' }) ``` -------------------------------- ### Get Brand Version from Client Hints Source: https://github.com/bowser-js/bowser/blob/master/docs/Parser.html Retrieves the version of a specific brand from Client Hints. Requires a Bowser Parser instance initialized with User-Agent and Client Hints data. ```javascript const parser = Bowser.getParser(UA, clientHints); const version = parser.getBrandVersion('Google Chrome'); console.log(version); // '131' ``` -------------------------------- ### Full Browser and System Information Source: https://github.com/bowser-js/bowser/blob/master/docs/index.html Get a comprehensive object containing browser, OS, platform, and engine details by parsing the User-Agent string. This provides a complete overview of the user's environment. ```javascript console.log(Bowser.parse(window.navigator.userAgent)); // outputs // { // browser: { // name: "Internet Explorer" // version: "11.0" // }, // os: { // name: "Windows" // version: "NT 6.3" // versionName: "8.1" // }, // platform: { // type: "desktop" // }, // engine: { // name: "Trident" // version: "7.0" // } // } ``` -------------------------------- ### Get Client Hints Data Source: https://github.com/bowser-js/bowser/blob/master/docs/Parser.html Retrieves the Client Hints object associated with the parser instance. This object contains information like platform and mobile status. Useful for accessing structured client hints. ```javascript const parser = Bowser.getParser(UA, clientHints); const hints = parser.getHints(); console.log(hints.platform); // 'Windows' console.log(hints.mobile); // false ``` -------------------------------- ### Install Bowser.js Source: https://context7.com/bowser-js/bowser/llms.txt Install Bowser.js using npm. Supports CommonJS, ES6 imports, AMD, and TypeScript. ```bash npm install bowser ``` -------------------------------- ### Using Bowser with User-Agent Client Hints Source: https://github.com/bowser-js/bowser/blob/master/docs/index.html Demonstrates how to initialize Bowser.js with both the User-Agent string and User-Agent Client Hints for enhanced browser detection. ```APIDOC ## Bowser.getParser with Client Hints ### Description Initializes the Bowser parser with both the User-Agent string and the User-Agent Client Hints object for more accurate browser detection. ### Method `Bowser.getParser(userAgent: string, userAgentData: UserAgentData | undefined)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript const browser = Bowser.getParser( window.navigator.userAgent, window.navigator.userAgentData ); console.log(`The current browser name is "${browser.getBrowserName()}"`); ``` ### Response #### Success Response (200) Returns a Bowser parser instance. #### Response Example ```json { "name": "Chrome", "version": "110.0.0" } ``` ``` -------------------------------- ### Get Parsed Result - Bowser.js Source: https://github.com/bowser-js/bowser/blob/master/docs/parser.js.html Returns a copy of the parsed result object. ```javascript getResult() { return Utils.assign({}, this.parsedResult); } ``` -------------------------------- ### Get Engine - Bowser.js Source: https://github.com/bowser-js/bowser/blob/master/docs/parser.js.html Retrieves the parsed engine information, parsing it if it hasn't been already. ```javascript getEngine() { if (this.parsedResult.engine) { return this.parsedResult.engine; } return this.parseEngine(); } ``` -------------------------------- ### getOS Source: https://github.com/bowser-js/bowser/blob/master/docs/Parser.html Returns the parsed operating system object. ```APIDOC ## getOS() ### Description Get OS ### Method `getOS` ### Returns * Type: `Object` ### Example ```javascript this.getOS(); { name: 'macOS', version: '10.11.12' } ``` ``` -------------------------------- ### Parsing with Client Hints using Bowser.parse Source: https://github.com/bowser-js/bowser/blob/master/docs/index.html Shows how to use the `Bowser.parse` method with both User-Agent string and Client Hints. ```APIDOC ## Bowser.parse with Client Hints ### Description Parses a User-Agent string and Client Hints to provide enhanced browser detection results. ### Method `Bowser.parse(userAgent: string, userAgentData: UserAgentData)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript console.log(Bowser.parse(window.navigator.userAgent, window.navigator.userAgentData)); ``` ### Response #### Success Response (200) Returns a detailed object with browser, OS, platform, and engine information, enhanced by Client Hints. #### Response Example ```json { "browser": { "name": "Chrome", "version": "110.0.0" }, "os": { "name": "Windows", "version": "10.0", "versionName": "10" }, "platform": { "type": "desktop" }, "engine": { "name": "Blink", "version": "110.0.0" } } ``` ``` -------------------------------- ### Get Browser Name Source: https://github.com/bowser-js/bowser/blob/master/docs/parser.js.html Retrieves the name of the browser. Optionally returns the name in lowercase. ```javascript return String(this.getBrowser().name).toLowerCase() || ''; ``` ```javascript return this.getBrowser().name || ''; ``` -------------------------------- ### Client Hints API with parser.getHints(), parser.hasBrand(), parser.getBrandVersion() Source: https://context7.com/bowser-js/bowser/llms.txt Access User-Agent Client Hints data using `getHints()`, `hasBrand()`, and `getBrandVersion()`. This is useful for accurately identifying browsers, especially Chromium-based ones. ```javascript // Simulated Client Hints object (normally navigator.userAgentData) const clientHints = { brands: [ { brand: "Google Chrome", version: "131" }, { brand: "Chromium", version: "131" }, { brand: "Not_A Brand", version: "24" }, ], mobile: false, platform: "Windows", platformVersion: "15.0.0", architecture: "x86", model: "", wow64: false, }; const parser = Bowser.getParser( "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 " + "(KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36", clientHints ); // Retrieve raw Client Hints object console.log(parser.getHints()); // { brands: [...], mobile: false, platform: 'Windows', ... } // Check for a specific brand console.log(parser.hasBrand("Google Chrome")); // true console.log(parser.hasBrand("DuckDuckGo")); // false // Get version of a brand console.log(parser.getBrandVersion("Google Chrome")); // "131" console.log(parser.getBrandVersion("Chromium")); // "131" console.log(parser.getBrandVersion("Firefox")); // undefined ``` -------------------------------- ### Create a Parser Instance with Bowser.getParser() Source: https://context7.com/bowser-js/bowser/llms.txt Create a Parser instance using Bowser.getParser() with a User-Agent string. Optionally provide Client Hints for better accuracy or set to true to parse lazily. ```javascript const Bowser = require("bowser"); // Basic usage const parser = Bowser.getParser( "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 " + "(KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" ); ``` ```javascript // With Client Hints (browser environment) const parserWithHints = Bowser.getParser( window.navigator.userAgent, window.navigator.userAgentData // navigator.userAgentData ); ``` ```javascript // Skip parsing on construction (lazy) const lazyParser = Bowser.getParser(window.navigator.userAgent, true); lazyParser.parse(); // parse manually later ``` ```javascript // Error: UA must be a string try { Bowser.getParser(null); } catch (e) { console.error(e.message); // "UserAgent should be a string" } ``` -------------------------------- ### getBrowserAlias(browserName) Source: https://github.com/bowser-js/bowser/blob/master/docs/global.html Gets a short alias or version name for a given browser name. ```APIDOC ## getBrowserAlias(browserName) ### Description Get short version/alias for a browser name. ### Example ```javascript getBrowserAlias('Microsoft Edge') // edge ``` ### Parameters #### Path Parameters * **browserName** (string) - The full name of the browser. ### Returns * **string** - The short alias for the browser. ``` -------------------------------- ### getOS Source: https://github.com/bowser-js/bowser/blob/master/docs/parser.js.html Retrieves the parsed operating system information. If not already parsed, it will parse the User-Agent string first. ```APIDOC ## getOS() ### Description Get OS. ### Returns - **Object** - An object containing OS details (e.g., name, version). ### Example ```javascript const parser = Bowser.getParser(UA); const osInfo = parser.getOS(); console.log(osInfo.name); // 'macOS' console.log(osInfo.version); // '10.11.12' ``` ``` -------------------------------- ### Get User Agent String Source: https://github.com/bowser-js/bowser/blob/master/docs/Parser.html Retrieves the raw User-Agent string that was parsed by the current Parser instance. ```javascript parser.getUA() ``` -------------------------------- ### Basic Browser Parsing Source: https://github.com/bowser-js/bowser/blob/master/docs/index.html Demonstrates the basic usage of Bowser.js for parsing User-Agent strings without Client Hints. ```APIDOC ## Bowser.getParser without Client Hints ### Description Parses a User-Agent string to extract browser information when Client Hints are not available. ### Method `Bowser.getParser(userAgent: string)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript const browser = Bowser.getParser(window.navigator.userAgent); console.log(browser.getBrowser()); ``` ### Response #### Success Response (200) Returns an object containing browser name and version. #### Response Example ```json { "name": "Internet Explorer", "version": "11.0" } ``` ``` ```APIDOC ## Bowser.parse without Client Hints ### Description Parses a User-Agent string to extract comprehensive browser, OS, platform, and engine details. ### Method `Bowser.parse(userAgent: string)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript console.log(Bowser.parse(window.navigator.userAgent)); ``` ### Response #### Success Response (200) Returns a detailed object with browser, OS, platform, and engine information. #### Response Example ```json { "browser": { "name": "Internet Explorer", "version": "11.0" }, "os": { "name": "Windows", "version": "NT 6.3", "versionName": "8.1" }, "platform": { "type": "desktop" }, "engine": { "name": "Trident", "version": "7.0" } } ``` ``` -------------------------------- ### getHints() Source: https://github.com/bowser-js/bowser/blob/master/docs/parser.js.html Retrieves the Client Hints data associated with the parser instance. ```APIDOC ## getHints() ### Description Gets the Client Hints data. ### Returns * `ClientHints|null` - The Client Hints object or null if not provided. ### Example ```javascript const parser = Bowser.getParser(UA, clientHints); const hints = parser.getHints(); console.log(hints.platform); // 'Windows' console.log(hints.mobile); // false ``` ``` -------------------------------- ### Get Engine Name - Bowser.js Source: https://github.com/bowser-js/bowser/blob/master/docs/parser.js.html Retrieves the name of the browser's engine. Optionally converts the name to lowercase. ```javascript getEngineName(toLowerCase) { if (toLowerCase) { return String(this.getEngine().name).toLowerCase() || ''; } return this.getEngine().name || ''; } ``` -------------------------------- ### Get Platform Name Source: https://github.com/bowser-js/bowser/blob/master/docs/Parser.html Retrieves the name of the platform. An optional boolean parameter can be passed to return the name in lowercase. ```javascript parser.getPlatformType(true) ``` -------------------------------- ### Get Browser Type by Alias Source: https://github.com/bowser-js/bowser/blob/master/docs/global.html Retrieves the full browser name from a given short alias. This is the inverse of getBrowserAlias. ```javascript getBrowserTypeByAlias('edge') // Microsoft Edge ``` -------------------------------- ### getOSVersion() Source: https://github.com/bowser-js/bowser/blob/master/docs/Parser.html Retrieves the full version string of the operating system. ```APIDOC ## getOSVersion() ### Description Retrieves the full version string of the operating system. ### Returns - **String**: The full version with dots (e.g., '10.11.12', '5.6'). ``` -------------------------------- ### Get Browser Alias - BowserJS Source: https://github.com/bowser-js/bowser/blob/master/docs/utils.js.html Retrieves a short alias for a given browser name. Useful for simplifying browser identification. ```javascript static getBrowserAlias(browserName) { return BROWSER_ALIASES_MAP[browserName]; } ``` -------------------------------- ### Accessing Client Hints Data Source: https://github.com/bowser-js/bowser/blob/master/docs/index.html Shows how to retrieve and query information from the Client Hints object using Bowser.js. ```APIDOC ## Bowser Parser Methods for Client Hints ### Description Provides methods to access and query the Client Hints data obtained during parser initialization. ### Methods - **`getHints()`**: Returns the full Client Hints object or null if not provided. - **`hasBrand(brandName: string)`**: Checks if a specific browser brand exists in the Client Hints. - **`getBrandVersion(brandName: string)`**: Retrieves the version of a specified browser brand. ### Request Example ```javascript const browser = Bowser.getParser( window.navigator.userAgent, window.navigator.userAgentData ); // Get the full Client Hints object const hints = browser.getHints(); // Returns the ClientHints object or null if not provided // Check if a specific brand exists if (browser.hasBrand('Google Chrome')) { console.log('This is Chrome!'); } // Get the version of a specific brand const chromeVersion = browser.getBrandVersion('Google Chrome'); console.log(`Chrome version: ${chromeVersion}`); ``` ### Response Example ```json { "brands": [ { "brand": "Google Chrome", "version": "131" }, { "brand": "Chromium", "version": "131" }, { "brand": "Not_A Brand", "version": "24" } ], "mobile": false, "platform": "Windows", "platformVersion": "15.0.0", "architecture": "x86", "model": "", "wow64": false } ``` ``` -------------------------------- ### Create a Parser Instance with User-Agent Source: https://github.com/bowser-js/bowser/blob/master/docs/bowser.js.html Use `getParser` to create a Parser instance with a given User-Agent string. This is useful when you need more control over the parsing process. ```javascript import Parser from './parser.js'; // ... inside Bowser class ... static getParser(UA, skipParsingOrHints = false, clientHints = null) { if (typeof UA !== 'string') { throw new Error('UserAgent should be a string'); } return new Parser(UA, skipParsingOrHints, clientHints); } ``` -------------------------------- ### Parsing with Client Hints Source: https://github.com/bowser-js/bowser/blob/master/README.md Use Bowser.parse() with both User-Agent string and Client Hints for enhanced detection. ```APIDOC ```javascript console.log(Bowser.parse(window.navigator.userAgent, window.navigator.userAgentData)); // Same output structure, but with enhanced detection from Client Hints ``` ``` -------------------------------- ### getEngine Source: https://github.com/bowser-js/bowser/blob/master/docs/Parser.html Returns the parsed engine object. ```APIDOC ## getEngine() ### Description Get parsed engine ### Method `getEngine` ### Returns * Type: `Object` ``` -------------------------------- ### Get Version Precision Count Source: https://github.com/bowser-js/bowser/blob/master/docs/global.html Returns the number of version components in a version string. Useful for comparing version granularities. ```javascript getVersionPrecision("1.10.3") // 3 ``` -------------------------------- ### Get Parsed Platform - Bowser.js Source: https://github.com/bowser-js/bowser/blob/master/docs/parser.js.html Parses the browser's platform information. It iterates through a list of platform parsers to find a match. ```javascript parsePlatform() { this.parsedResult.platform = {}; const platform = Utils.find(platformParsersList, (_platform) => { if (typeof _platform.test === 'function') { return _platform.test(this); } if (Array.isArray(_platform.test)) { return _platform.test.some(condition => this.test(condition)); } throw new Error("Browser's test function is not valid"); }); if (platform) { this.parsedResult.platform = platform.describe(this.getUA()); } return this.parsedResult.platform; } ``` -------------------------------- ### is(anything, includingAliasopt) Source: https://github.com/bowser-js/bowser/blob/master/docs/Parser.html Checks if the browser, OS, or platform matches the provided string, optionally including aliases. ```APIDOC ## is(anything, includingAliasopt) ### Description Checks if the browser, OS, or platform matches the provided string, optionally including aliases. ### Parameters #### Path Parameters - **anything** (String) - Required - The string to check against. - **includingAlias** (Boolean) - Optional - Defaults to `false`. Whether to include aliases in the comparison. ### Returns - **Boolean**: True if a match is found, false otherwise. ``` -------------------------------- ### Get Version Precision - JavaScript Source: https://github.com/bowser-js/bowser/blob/master/docs/utils.js.html Calculates the number of dot-separated parts in a version string. Useful for determining the complexity of a version number. ```javascript static getVersionPrecision(version) { return version.split('.').length; } ``` -------------------------------- ### OS Details: getOS(), getOSName(), getOSVersion() Source: https://context7.com/bowser-js/bowser/llms.txt Retrieve the parsed OS object, its name, or its version. The `versionName` field maps numeric versions to human-readable names. ```APIDOC ## `parser.getOS()` / `parser.getOSName()` / `parser.getOSVersion()` — OS details Retrieve the parsed OS object, its name, or its version. The `versionName` field maps numeric versions to human-readable names (e.g., `"Catalina"`, `"Nougat"`, `"NT 6.3"` → `"8.1"`). ```javascript const parser = Bowser.getParser( "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 " + "(KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36" ); console.log(parser.getOS()); // { name: "Windows", version: "NT 6.3", versionName: "8.1" } console.log(parser.getOSName()); // "Windows" console.log(parser.getOSName(true)); // "windows" (toLowerCase) console.log(parser.getOSVersion()); // "NT 6.3" // macOS example const macParser = Bowser.getParser( "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 " + "(KHTML, like Gecko) Chrome/100.0.0.0 Safari/537.36" ); console.log(macParser.getOS()); // { name: "macOS", version: "10.14.6", versionName: "Mojave" } ``` ``` -------------------------------- ### Bowser.getParser(UA, [clientHints]) Source: https://context7.com/bowser-js/bowser/llms.txt Creates a Parser instance for a given User-Agent string. Optionally accepts Client Hints for improved accuracy or a boolean to defer parsing. ```APIDOC ## Bowser.getParser(UA, [clientHints]) — Create a Parser instance Returns a `Parser` object for the given User-Agent string. Accepts an optional second argument of `navigator.userAgentData` (Client Hints) for improved detection accuracy on modern browsers, or a boolean `true` to skip parsing on construction. ### Parameters #### Path Parameters - **UA** (string) - Required - The User-Agent string to parse. - **clientHints** (object | boolean) - Optional - `navigator.userAgentData` object or `true` to skip parsing on construction. ### Request Example ```javascript const Bowser = require("bowser"); // Basic usage const parser = Bowser.getParser( "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 " + "(KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" ); // With Client Hints (browser environment) const parserWithHints = Bowser.getParser( window.navigator.userAgent, window.navigator.userAgentData // navigator.userAgentData ); // Skip parsing on construction (lazy) const lazyParser = Bowser.getParser(window.navigator.userAgent, true); lazyParser.parse(); // parse manually later // Error: UA must be a string try { Bowser.getParser(null); } catch (e) { console.error(e.message); // "UserAgent should be a string" } ``` ``` -------------------------------- ### Get Parsed Result Object Source: https://github.com/bowser-js/bowser/blob/master/docs/Parser.html Returns the complete parsed result object, which contains all detected information about the browser, OS, and platform. ```javascript parser.getResult() ``` -------------------------------- ### getOS() Source: https://github.com/bowser-js/bowser/blob/master/docs/Parser.html Retrieves the name of the operating system (e.g., macOS, Windows, Linux). ```APIDOC ## getOS() ### Description Retrieves the name of the operating system. ### Returns - **String**: The name of the OS (e.g., macOS, Windows, Linux). ``` -------------------------------- ### Get Browser Alias Source: https://github.com/bowser-js/bowser/blob/master/docs/global.html Provides a short alias or common name for a given browser name. Useful for simplifying browser identification. ```javascript getBrowserAlias('Microsoft Edge') // edge ``` -------------------------------- ### Get OS Information Source: https://github.com/bowser-js/bowser/blob/master/docs/Parser.html Retrieves the parsed operating system object, including its name and version. This method is part of the core parsing functionality. ```javascript this.getOS(); { name: 'macOS', version: '10.11.12' } ``` -------------------------------- ### Parse User Agent with Client Hints Source: https://github.com/bowser-js/bowser/blob/master/README.md Use `Bowser.getParser` with both User-Agent and User-Agent Data to leverage Client Hints for enhanced browser detection. Falls back to User-Agent parsing if Client Hints are unavailable. ```javascript const browser = Bowser.getParser( window.navigator.userAgent, window.navigator.userAgentData ); // Get the full Client Hints object const hints = browser.getHints(); // Returns the ClientHints object or null if not provided // Check if a specific brand exists if (browser.hasBrand('Google Chrome')) { console.log('This is Chrome!'); } // Get the version of a specific brand const chromeVersion = browser.getBrandVersion('Google Chrome'); console.log(`Chrome version: ${chromeVersion}`); ``` -------------------------------- ### isOS Source: https://github.com/bowser-js/bowser/blob/master/docs/parser.js.html Checks if the current operating system name matches the provided string. ```APIDOC ## isOS ### Description Checks if the current operating system name matches the provided string. ### Method Signature `isOS(osName: string): boolean` ### Parameters #### Path Parameters - **osName** (string) - The string to compare with the OS name. ### Returns - **boolean** - `true` if the OS name matches, `false` otherwise. ``` -------------------------------- ### Get Android Version Name Source: https://github.com/bowser-js/bowser/blob/master/docs/global.html Retrieves the human-readable name for a given Android version string. Useful for displaying user-friendly OS information. ```javascript getAndroidVersionName("7.0") // 'Nougat' ``` -------------------------------- ### Bowser.parse Source: https://github.com/bowser-js/bowser/blob/master/docs/Bowser.html Creates a Parser instance and immediately retrieves the parsed result. This is a convenience method for quickly getting parsed user agent information. ```APIDOC ## Bowser.parse ### Description Creates a [Parser](Parser.html) instance and immediately runs `Parser.getResult`. This method provides a quick way to obtain parsed user agent information, optionally using User-Agent Client Hints. ### Method static ### Parameters #### Parameters - **UA** (String) - Required - UserAgent string - **clientHints** (Object) - Optional - Defaults to `null`. User-Agent Client Hints data (navigator.userAgentData). ### Returns - [ParsedResult](global.html#ParsedResult): The result of parsing the user agent string. ### Request Example ```javascript const result = Bowser.parse(window.navigator.userAgent); // With User-Agent Client Hints const result = Bowser.parse( window.navigator.userAgent, window.navigator.userAgentData ); ``` ``` -------------------------------- ### getUA Source: https://github.com/bowser-js/bowser/blob/master/docs/parser.js.html Returns the original User-Agent string that was used to initialize the parser. ```APIDOC ## getUA() ### Description Get UserAgent string of current Parser instance. ### Returns - **String** - User-Agent String of the current object. ### Example ```javascript const parser = Bowser.getParser(UA); const uaString = parser.getUA(); console.log(uaString); ``` ``` -------------------------------- ### Get Engine Details with Bowser.js Source: https://context7.com/bowser-js/bowser/llms.txt Retrieve the rendering engine name and version. The getEngineName method can return the name in lowercase if the second argument is true. ```javascript const ieParser = Bowser.getParser( "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)" ); console.log(ieParser.getEngine()); // { name: "Trident", version: "6.0" } const chromeParser = Bowser.getParser( "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 " + "(KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36" ); console.log(chromeParser.getEngineName()); // "Blink" console.log(chromeParser.getEngineName(true)); // "blink" ``` -------------------------------- ### Get Full Parsed Result with parser.getResult() Source: https://context7.com/bowser-js/bowser/llms.txt Retrieve the complete ParsedResult object, containing browser, OS, platform, and engine details, using parser.getResult(). ```javascript const parser = Bowser.getParser( "Mozilla/5.0 (Linux; Android 13; Pixel 7) AppleWebKit/537.36 " + "(KHTML, like Gecko) Chrome/112.0.0.0 Mobile Safari/537.36" ); const result = parser.getResult(); console.log(result); // { // browser: { name: "Chrome", version: "112.0.0.0" }, // os: { name: "Android", version: "13", versionName: undefined }, // platform: { type: "mobile", vendor: "Google", model: "Pixel 7" }, // engine: { name: "Blink", version: "112.0.0.0" } // } ``` -------------------------------- ### Platform Details: getPlatform(), getPlatformType() Source: https://context7.com/bowser-js/bowser/llms.txt Retrieve the platform object (`type`, `vendor`, `model`) or just the type string (`"desktop"`, `"mobile"`, `"tablet"`, `"tv"`, `"bot"`). ```APIDOC ## `parser.getPlatform()` / `parser.getPlatformType()` — Platform details Retrieve the platform object (`type`, `vendor`, `model`) or just the type string (`"desktop"`, `"mobile"`, `"tablet"`, `"tv"`, `"bot"`). ```javascript const mobileParser = Bowser.getParser( "Mozilla/5.0 (iPhone; CPU iPhone OS 16_3 like Mac OS X) " + "AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.3 Mobile/15E148 Safari/604.1" ); console.log(mobileParser.getPlatform()); // { type: "mobile", vendor: "Apple", model: "iPhone" } console.log(mobileParser.getPlatformType()); // "mobile" console.log(mobileParser.getPlatformType(true)); // "mobile" (always lower) const desktopParser = Bowser.getParser( "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 " + "(KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" ); console.log(desktopParser.getPlatformType()); // "desktop" ``` ``` -------------------------------- ### Bowser.getParser Source: https://github.com/bowser-js/bowser/blob/master/docs/bowser.js.html Creates a Parser instance for detailed user agent analysis. It can optionally use User-Agent Client Hints for more accurate detection. ```APIDOC ## Bowser.getParser ### Description Creates a `Parser` instance for detailed user agent analysis. It can optionally use User-Agent Client Hints for more accurate detection. ### Method `static getParser(UA, skipParsingOrHints, clientHints)` ### Parameters - **UA** (String) - UserAgent string. - **skipParsingOrHints** (Boolean|Object) - Optional. Either a boolean to skip parsing, or a ClientHints object (`navigator.userAgentData`). Defaults to `false`. - **clientHints** (Object) - Optional. User-Agent Client Hints data (`navigator.userAgentData`). ### Returns - `Parser` - A new Parser instance. ### Throws - `Error` - when UA is not a String. ### Examples ```javascript const parser = Bowser.getParser(window.navigator.userAgent); const result = parser.getResult(); // With User-Agent Client Hints const parserWithHints = Bowser.getParser(window.navigator.userAgent, window.navigator.userAgentData); ``` ``` -------------------------------- ### Get Browser Type by Alias - BowserJS Source: https://github.com/bowser-js/bowser/blob/master/docs/utils.js.html Retrieves the full browser name from a given short alias. Returns an empty string if the alias is not found. ```javascript static getBrowserTypeByAlias(browserAlias) { return BROWSER_MAP[browserAlias] || ''; } ``` -------------------------------- ### parser.getHints() / parser.hasBrand(name) / parser.getBrandVersion(name) Source: https://context7.com/bowser-js/bowser/llms.txt Provides access to User-Agent Client Hints data when available. These methods are useful for more accurate browser identification, especially for Chromium-based browsers. ```APIDOC ## `parser.getHints()` / `parser.hasBrand(name)` / `parser.getBrandVersion(name)` — Client Hints API ### Description Access User-Agent Client Hints data when provided. Useful for accurately identifying Chromium-based browsers that share similar UA strings (e.g., DuckDuckGo browser). ### Methods - **`getHints()`**: Retrieves the raw Client Hints object. - **`hasBrand(name)`**: Checks if a specific brand is present in the Client Hints. - **`getBrandVersion(name)`**: Retrieves the version of a specific brand from the Client Hints. ### Parameters #### `hasBrand(name)` and `getBrandVersion(name)` - **name** (string) - Required - The name of the brand to check or retrieve the version for. ### Request Example ```javascript // Simulated Client Hints object (normally navigator.userAgentData) const clientHints = { brands: [ { brand: "Google Chrome", version: "131" }, { brand: "Chromium", version: "131" }, { brand: "Not_A Brand", version: "24" }, ], mobile: false, platform: "Windows", platformVersion: "15.0.0", architecture: "x86", model: "", wow64: false, }; const parser = Bowser.getParser("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36", clientHints); // Retrieve raw Client Hints object console.log(parser.getHints()); // { brands: [...], mobile: false, platform: 'Windows', ... } // Check for a specific brand console.log(parser.hasBrand("Google Chrome")); // true console.log(parser.hasBrand("DuckDuckGo")); // false // Get version of a brand console.log(parser.getBrandVersion("Google Chrome")); // "131" console.log(parser.getBrandVersion("Chromium")); // "131" console.log(parser.getBrandVersion("Firefox")); // undefined ``` ### Response - **`getHints()`**: Returns an object containing the Client Hints data. - **`hasBrand(name)`**: Returns `true` if the brand exists, `false` otherwise. - **`getBrandVersion(name)`**: Returns the version string of the brand, or `undefined` if the brand is not found. ``` -------------------------------- ### Get First Match from String Source: https://github.com/bowser-js/bowser/blob/master/docs/utils.js.html Extracts the first captured group from a string using a regular expression. Returns an empty string if no match is found. ```javascript static getFirstMatch(regexp, ua) { const match = ua.match(regexp); return (match && match.length > 0 && match[1]) || ''; } ``` -------------------------------- ### Get Browser Details with parser.getBrowser() Source: https://context7.com/bowser-js/bowser/llms.txt Extract browser name and version using parser.getBrowser(). Use parser.getBrowserName() for just the name (optionally lowercase) and parser.getBrowserVersion() for the version string. ```javascript const parser = Bowser.getParser( "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0" ); console.log(parser.getBrowser()); // { name: "Firefox", version: "115.0" } ``` ```javascript console.log(parser.getBrowserName()); // "Firefox" ``` ```javascript console.log(parser.getBrowserName(true)); // toLowerCase flag // "firefox" ``` ```javascript console.log(parser.getBrowserVersion()); // "115.0" ``` -------------------------------- ### getHints Source: https://github.com/bowser-js/bowser/blob/master/docs/Parser.html Retrieves the Client Hints data associated with the User-Agent. ```APIDOC ## getHints() ### Description Get Client Hints data ### Method `getHints` ### Returns * Type: `[ClientHints](global.html#ClientHints) | null` ### Example ```javascript const parser = Bowser.getParser(UA, clientHints); const hints = parser.getHints(); console.log(hints.platform); // 'Windows' console.log(hints.mobile); // false ``` ``` -------------------------------- ### Engine Details: getEngine(), getEngineName() Source: https://context7.com/bowser-js/bowser/llms.txt Retrieve the rendering engine name and version. ```APIDOC ## `parser.getEngine()` / `parser.getEngineName()` — Engine details Retrieve the rendering engine name and version. ```javascript const ieParser = Bowser.getParser( "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)" ); console.log(ieParser.getEngine()); // { name: "Trident", version: "6.0" } const chromeParser = Bowser.getParser( "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 " + "(KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36" ); console.log(chromeParser.getEngineName()); // "Blink" console.log(chromeParser.getEngineName(true)); // "blink" ``` ``` -------------------------------- ### Get Browser Version Name Source: https://github.com/bowser-js/bowser/blob/master/docs/utils.js.html Maps internal version numbers to codenames like 'Froyo', 'Gingerbread', etc. Used for identifying specific Android versions. ```javascript if (v[0] === 2 && v[1] === 2) return 'Froyo'; if (v[0] === 2 && v[1] > 2) return 'Gingerbread'; if (v[0] === 3) return 'Honeycomb'; if (v[0] === 4 && v[1] < 1) return 'Ice Cream Sandwich'; if (v[0] === 4 && v[1] < 4) return 'Jelly Bean'; if (v[0] === 4 && v[1] >= 4) return 'KitKat'; if (v[0] === 5) return 'Lollipop'; if (v[0] === 6) return 'Marshmallow'; if (v[0] === 7) return 'Nougat'; if (v[0] === 8) return 'Oreo'; if (v[0] === 9) return 'Pie'; return undefined; ``` -------------------------------- ### Get Second Match from RegExp Source: https://github.com/bowser-js/bowser/blob/master/docs/global.html Extracts the second matched substring from a string using a regular expression. This is useful when a pattern may have multiple capturing groups. ```javascript getSecondMatch(regexp, ua) ``` -------------------------------- ### Parse User Agent with Bowser.parse() and Client Hints Source: https://github.com/bowser-js/bowser/blob/master/README.md Use `Bowser.parse()` with both User-Agent and User-Agent Data to enhance parsing accuracy with Client Hints. This provides the same output structure but with improved detection capabilities. ```javascript console.log(Bowser.parse(window.navigator.userAgent, window.navigator.userAgentData)); // Same output structure, but with enhanced detection from Client Hints ``` -------------------------------- ### Get macOS Version Name Source: https://github.com/bowser-js/bowser/blob/master/docs/global.html Translates a macOS version number string into its corresponding release name. Helpful for displaying OS information in a more readable format. ```javascript getMacOSVersionName("10.14") // 'Mojave' ``` -------------------------------- ### Check OS Name Source: https://github.com/bowser-js/bowser/blob/master/docs/parser.js.html Checks if the operating system name matches the provided string. Case-insensitive comparison. ```javascript isOS(osName) { return this.getOSName(true) === String(osName).toLowerCase(); } ``` -------------------------------- ### Get First Match from RegExp Source: https://github.com/bowser-js/bowser/blob/master/docs/global.html Extracts the first matched substring from a string using a regular expression. Useful for parsing user agent strings or other text. ```javascript getFirstMatch(regexp, ua) ``` -------------------------------- ### getPlatform() Source: https://github.com/bowser-js/bowser/blob/master/docs/Parser.html Retrieves the parsed platform information. ```APIDOC ## getPlatform() ### Description Retrieves the parsed platform information. ### Returns - **Object**: The parsed platform details. ``` -------------------------------- ### Get Android Version Name Source: https://github.com/bowser-js/bowser/blob/master/docs/utils.js.html Translates Android version numbers (e.g., '7.0', '4.4') into their codenames like 'Nougat' or 'KitKat'. Supports versions from 1.5 onwards. ```javascript static getAndroidVersionName(version) { const v = version.split('.').splice(0, 2).map(s => parseInt(s, 10) || 0); v.push(0); if (v[0] === 1 && v[1] < 5) return undefined; if (v[0] === 1 && v[1] < 6) return 'Cupcake'; if (v[0] === 1 && v[1] >= 6) return 'Donut'; if (v[0] === 2 && v[1] < 2) return 'Eclair'; } ``` -------------------------------- ### Get Second Match from String Source: https://github.com/bowser-js/bowser/blob/master/docs/utils.js.html Extracts the second captured group from a string using a regular expression. Returns an empty string if no match is found or if there is no second group. ```javascript static getSecondMatch(regexp, ua) { const match = ua.match(regexp); return (match && match.length > 1 && match[2]) || ''; } ``` -------------------------------- ### getPlatform Source: https://github.com/bowser-js/bowser/blob/master/docs/parser.js.html Retrieves the parsed platform information. If not already parsed, it will parse the User-Agent string first. ```APIDOC ## getPlatform() ### Description Get parsed platform. ### Returns - **Object** - An object containing platform details. ### Example ```javascript const parser = Bowser.getParser(UA); const platformInfo = parser.getPlatform(); console.log(platformInfo); // { type: 'desktop', vendor: 'Apple', model: 'Macintosh' } ``` ``` -------------------------------- ### Basic Browser Detection with User-Agent String Source: https://github.com/bowser-js/bowser/blob/master/docs/index.html Perform basic browser detection using only the User-Agent string when Client Hints are not available. This method is less accurate for some modern browsers. ```javascript const browser = Bowser.getParser(window.navigator.userAgent); console.log(browser.getBrowser()); // outputs // { // name: "Internet Explorer" // version: "11.0" // } ``` -------------------------------- ### Get Platform Details with Bowser.js Source: https://context7.com/bowser-js/bowser/llms.txt Retrieve the platform object (type, vendor, model) or just the type string. Supported types include 'desktop', 'mobile', 'tablet', 'tv', and 'bot'. ```javascript const mobileParser = Bowser.getParser( "Mozilla/5.0 (iPhone; CPU iPhone OS 16_3 like Mac OS X) " + "AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.3 Mobile/15E148 Safari/604.1" ); console.log(mobileParser.getPlatform()); // { type: "mobile", vendor: "Apple", model: "iPhone" } console.log(mobileParser.getPlatformType()); // "mobile" console.log(mobileParser.getPlatformType(true)); // "mobile" (always lower) const desktopParser = Bowser.getParser( "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 " + "(KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" ); console.log(desktopParser.getPlatformType()); // "desktop" ``` -------------------------------- ### Get Browser Properties Source: https://github.com/bowser-js/bowser/blob/master/README.md Use Bowser.getParser to extract browser details like name and version from the user agent string. This is useful for conditional logic based on browser capabilities. ```javascript const browser = Bowser.getParser(window.navigator.userAgent); console.log(`The current browser name is "${browser.getBrowserName()}"`); // The current browser name is "Internet Explorer" ```