### Install WhichBrowser via NPM Source: https://github.com/whichbrowser/parser-javascript/blob/master/README.md Install the WhichBrowser library using NPM. It is recommended not to pin to a specific version to receive updates. ```bash npm install which-browser ``` -------------------------------- ### Install WhichBrowser via Yarn Source: https://github.com/whichbrowser/parser-javascript/blob/master/README.md Install the WhichBrowser library using Yarn. It is recommended not to pin to a specific version to receive updates. ```bash yarn add which-browser ``` -------------------------------- ### Basic HTTP Server with WhichBrowser Source: https://github.com/whichbrowser/parser-javascript/blob/master/README.md A short example demonstrating how to create a basic HTTP server that uses WhichBrowser to parse request headers and respond with browser information. ```javascript const WhichBrowser = require("which-browser"); const http = require("http"); const port = 3000; const server = http.createServer((request, response) => { const result = new WhichBrowser(request.headers); response.end(result.toString()); }); server.listen(port, (err) => { if (err) { return console.log("Something is broken ¯\_(ツ)_/¯", err); } console.log(`Server is listening on port ${port} ✌(-‿-)✌`); }); ``` -------------------------------- ### Family Object Source: https://github.com/whichbrowser/parser-javascript/blob/master/README.md Provides information about the family to which a browser or operating system belongs, including its name and version. It offers methods to get the family name, version, and a human-readable string. ```APIDOC ## Family Object ### Description An object of the `Family` class is used for the `family` property of the `Browser` and `Os` object and contains a number of properties. If a property is not applicable in this situation it will be null or undefined. ### Properties - `name` (string) - a string containing the name of the family - `version` (object) - a version object containing information about the version of the family ### Functions - `getName()` - Get the name of the family - `getVersion()` - Get the version of the family - `toString()` - Get a human readable representation of the family ``` -------------------------------- ### Get Human-Readable Browser Identification Source: https://github.com/whichbrowser/parser-javascript/blob/master/README.md Use the `toString()` method on the WhichBrowser result object to get a human-readable string identifying the browser and OS. ```javascript `You are using ${result.toString()}`; ``` -------------------------------- ### Compare OS Version Source: https://github.com/whichbrowser/parser-javascript/blob/master/README.md Demonstrates how to compare the detected OS version against a specific version string or using comparison operators. ```javascript result.os.version.is("10.7.4"); // true result.os.version.is("10.7"); // true result.os.version.is("10"); // true result.os.version.is("10.0"); // false result.os.version.is(">", "10"); // false result.os.version.is(">", "10.7"); // false result.os.version.is(">", "10.7.3"); // true ``` -------------------------------- ### Using Object Source: https://github.com/whichbrowser/parser-javascript/blob/master/README.md Contains information about the webview being used, including its name and version. It provides methods to retrieve the webview name, version, and a human-readable string. ```APIDOC ## Using Object ### Description An object of the `Using` class is used for the `using` property of the `Browser` object and contains a number of properties. If a property is not applicable in this situation it will be null or undefined. ### Properties - `name` (string) - a string containing the name of the webview - `version` (object) - a version object containing information about the version of the webview ### Functions - `getName()` - Get the name of the webview - `getVersion()` - Get the version of the webview - `toString()` - Get a human readable representation of the webview ``` -------------------------------- ### Access Browser Name and Version Source: https://github.com/whichbrowser/parser-javascript/blob/master/README.md Construct a string with the browser's name and its version, accessed directly. ```javascript `"${result.browser.name} ${result.browser.version.toString()}"` ``` -------------------------------- ### Compare OS Version Source: https://github.com/whichbrowser/parser-javascript/blob/master/README.md Use the `is()` method on the OS version object to perform version comparisons. ```javascript result.os.version.is("<", "10.7.4"); // false ``` -------------------------------- ### Instantiate WhichBrowser with User-Agent String Source: https://github.com/whichbrowser/parser-javascript/blob/master/README.md Create a new WhichBrowser instance using only the user-agent string when request headers are not available. ```javascript const result = new WhichBrowser(request.headers['user-agent'])); ``` -------------------------------- ### Check Specific OS Version Source: https://github.com/whichbrowser/parser-javascript/blob/master/README.md Use the `isOs()` method to check if the operating system matches a specific name and optionally compare its version. ```javascript result.isOs("iOS", ">=", "8"); // false ``` -------------------------------- ### Check Specific OS Name Source: https://github.com/whichbrowser/parser-javascript/blob/master/README.md Use the `isOs()` method to check if the operating system matches a specific name. ```javascript result.isOs("OS X"); // true ``` -------------------------------- ### Enable Simple Caching Source: https://github.com/whichbrowser/parser-javascript/blob/master/README.md Enable caching by setting `cache: WhichBrowser.SIMPLE_CACHE` in the options. This speeds up subsequent requests by using cached results. ```javascript const result = new WhichBrowser(request.header, { cache: WhichBrowser.SIMPLE_CACHE, }); ``` -------------------------------- ### Import WhichBrowser Source: https://github.com/whichbrowser/parser-javascript/blob/master/README.md Import the WhichBrowser library into your JavaScript project. ```javascript const WhichBrowser = require("which-browser"); ``` -------------------------------- ### Os Object Source: https://github.com/whichbrowser/parser-javascript/blob/master/README.md Provides information about the operating system, including its name, version, and family. It offers methods to check the OS family and retrieve its name, version, and a human-readable string. ```APIDOC ## Os Object ### Description An object of the `Os` class is used for the `os` property of the main `WhichBrowser` object and contains a number of properties. If a property is not applicable in this situation it will be null or undefined. ### Properties - `name` (string) - a string containing the name of the operating system - `version` (object) - a version object containing information about the version of the operating system - `family` (object) - an object that contains information about to which family this operating system belongs ### Functions - `isFamily(name)` - Does the family of this operating system have this name, or does the operating system itself have this name. - `getName()` - Get the name of the operating system - `getVersion()` - Get the version of the operating system - `toString()` - Get a human readable representation of the detected operating system ``` -------------------------------- ### Instantiate WhichBrowser with Request Headers Source: https://github.com/whichbrowser/parser-javascript/blob/master/README.md Create a new WhichBrowser instance using the request headers for detailed browser detection. ```javascript const result = new WhichBrowser(request.headers); ``` -------------------------------- ### Access OS Information Directly Source: https://github.com/whichbrowser/parser-javascript/blob/master/README.md Access the operating system's name and version directly from the result object. ```javascript result.os.toString(); // OS X Mountain Lion 10.8 ``` -------------------------------- ### Compare Browser Version Source: https://github.com/whichbrowser/parser-javascript/blob/master/README.md Use the `is()` method on the browser version object to perform version comparisons. ```javascript result.browser.version.is(">", 26); // true ``` -------------------------------- ### Version Object Source: https://github.com/whichbrowser/parser-javascript/blob/master/README.md Represents version information with properties for the original value, alias, nickname, and details. It includes a powerful `is()` function for comparing versions with optional comparison operators. ```APIDOC ## Version Object ### Description An object of the `Version` class is used for the `version` property of the `Browser`, `Engine` and `Os` object and contains a number of properties and functions. If a property is not applicable in this situation it will be null or undefined. ### Properties - `value` (string) - a string containing the original version number. - `alias` (string) - a string containing an alias for the version number, ie. 'XP' for Windows '5.1'. - `nickname` (string) - a string containing a nickname for the version number, ie. 'Mojave' for OS X '10.14'. - `details` (integer) - an integer containing the number of digits of the version number that should be printed. ### Functions - `is(version)` or `is(comparison, version)` - Using this function it is easy to compare a version to another version. If you specify only one argument, this function will return if the versions are the same. You can also specify two arguments, in that case the first argument contains the comparison operator, such as `<`, `<=`, `=`, `=>` or `>`. The second argument is the version you want to compare it to. You can use versions like `10`, `10.7` or `'10.7.4'`, but be aware that `10` is not the same as `10.0`. For example if our OS version is `10.7.4`: ```js result.os.version.is("10.7.4"); // true result.os.version.is("10.7"); // true result.os.version.is("10"); // true result.os.version.is("10.0"); // false result.os.version.is(">", "10"); // false result.os.version.is(">", "10.7"); // false result.os.version.is(">", "10.7.3"); // true ``` ``` -------------------------------- ### Check Multiple Browser Types Source: https://github.com/whichbrowser/parser-javascript/blob/master/README.md Use the `isType()` method with multiple arguments to check against several browser categories. ```javascript result.isType("mobile", "tablet", "media", "gaming:portable"); // false ``` -------------------------------- ### Check Browser Type Source: https://github.com/whichbrowser/parser-javascript/blob/master/README.md Use the `isType()` method to check if the browser belongs to a specific category like 'desktop'. ```javascript result.isType("desktop"); // true ``` -------------------------------- ### Access Browser Version Value Source: https://github.com/whichbrowser/parser-javascript/blob/master/README.md Access the detailed value of the browser's version. ```javascript result.browser.version.value; // 27.0.1453.110 ``` -------------------------------- ### Device Object Source: https://github.com/whichbrowser/parser-javascript/blob/master/README.md Represents information about the detected device, including its type, subtype, manufacturer, and model. It provides methods to retrieve the manufacturer, model, and a human-readable string. ```APIDOC ## Device Object ### Description An object of the `Device` class is used for the `device` property of the main `Parser` object and contains a number of properties. If a property is not applicable in this situation it will be null or undefined. ### Properties - `type` (string) - a string containing the type of the browser. Possible values include: desktop, mobile, pda, dect, tablet, gaming, ereader, media, headset, watch, emulator, television, monitor, camera, printer, signage, whiteboard, devboard, inflight, appliance, gps, car, pos, bot, projector. - `subtype` (string) - a string containing the subtype of the browser. If `type` is "mobile", possible values include: feature, smart. If `type` is "gaming", possible values include: console, portable. - `identified` (boolean) - a boolean that is true if the device has been positively identified. - `manufacturer` (string) - a string containing the manufacturer of the device, ie. 'Apple' or 'Samsung'. - `model` (string) - as string containing the model of the device, ie. 'iPhone' or 'Galaxy S4'. ### Functions - `getManufacturer()` - Get the name of the manufacturer - `getModel()` - Get the name of the model - `toString()` - Get a human readable representation of the detected device ``` -------------------------------- ### Check Specific Rendering Engine Source: https://github.com/whichbrowser/parser-javascript/blob/master/README.md Use the `isEngine()` method to check if the browser uses a specific rendering engine. ```javascript result.isEngine("Blink"); // true ``` -------------------------------- ### Set Cache Expiry Time Source: https://github.com/whichbrowser/parser-javascript/blob/master/README.md Configure cache expiry by setting `cacheExpires` to the desired duration in seconds. A value of 0 disables expiry for that result. ```javascript const result = new WhichBrowser(request.header, { cache: WhichBrowser.SIMPLE_CACHE, cacheExpires: 300, }); ``` -------------------------------- ### Access Browser Information Directly Source: https://github.com/whichbrowser/parser-javascript/blob/master/README.md Access the browser's name and version directly from the result object. ```javascript result.browser.toString(); // Chrome 27 ``` -------------------------------- ### Check Specific Browser Version Source: https://github.com/whichbrowser/parser-javascript/blob/master/README.md Use the `isBrowser()` method to check if the browser is a specific one and optionally compare its version. ```javascript result.isBrowser("Maxthon", "<", "4.0.5"); // false ``` -------------------------------- ### WhichBrowser Object Functions Source: https://github.com/whichbrowser/parser-javascript/blob/master/README.md Functions available on the main WhichBrowser object for querying detected browser information. ```APIDOC ## WhichBrowser Object Functions ### `getType()` **Description**: Returns the `type` and `subtype` property of the `device` object. If a subtype is present it is concatenated to the type and seperated by a semicolor, for example: `mobile:smart` or `gaming:portable`. If the subtype is not applicable, it just return the type, for example: `desktop` or `ereader`. ### `isType(type [,type [,type [,type]]])` **Description**: If a single argument is used, the function returns `true` if the argument matches the `type` propery of `device` object. The argument can optionally also provide a subtype by concatenating it to the type and seperating it with a semicolon. It can use multiple arguments in which case the function returns `true` if one of the arguments matches. If none of the arguments matches, it returns `false`. ### `isMobile()` **Description**: Return `true` if the browser is a mobile device, like a phone, tablet, ereader, camera, portable media player, watch or portable gaming console. Otherwise it returns `false`. ### `isBrowser($name [, comparison, version])` **Description**: Is used to query the `name` and `version` property of the `browser` object. The funcion can contain a single argument to a simple comparison based on `name`, or three arguments to compare both `name` and `version`. The first argument always contains the name of the browser. The second arguments is a string that can container either `<`, `<=`, `=`, `=>` or `>`. The third is an integer, float or string that contains the version. You can use versions like `10`, `10.7` or `'10.7.4'`. For more information about how version comparisons are performed, please see the `is()` function of the `Version` object. ### `isEngine(name [, comparison, version])` **Description**: Is used to query the `name` and `version` property of the `engine` object. This function works in exactly the same way as `isBrowser`. ### `isOs(name [, comparison, version])` **Description**: Is used to query the `name` and `version` property of the `os` object. This function works in exactly the same way as `isBrowser`. ### `isDetected()` **Description**: Is there actually some browser detected, or did we fail to detect anything? ### `toString()` **Description**: Get a human readable representation of the detected browser, including operating system and device information. ``` -------------------------------- ### Access Engine Name Directly Source: https://github.com/whichbrowser/parser-javascript/blob/master/README.md Access the rendering engine's name property directly. ```javascript result.engine.name; // Blink ``` -------------------------------- ### Browser Object Functions Source: https://github.com/whichbrowser/parser-javascript/blob/master/README.md Functions available on the Browser object for querying browser-specific details. ```APIDOC ## Browser Object Functions ### `isFamily(name)` **Description**: Does the family of this browser have this name, or does the browser itself have this name. ### `isUsing(name)` **Description**: Is the browser using a webview using with the provided name. ### `getName()` **Description**: Get the name of the browser. ### `getVersion()` **Description**: Get the version of the browser. ### `toString()` **Description**: Get a human readable representation of the detected browser. ``` -------------------------------- ### Engine Object Functions Source: https://github.com/whichbrowser/parser-javascript/blob/master/README.md Functions available on the Engine object for querying rendering engine details. ```APIDOC ## Engine Object Functions ### `getName()` **Description**: Get the name of the rendering engine. ### `getVersion()` **Description**: Get the version of the rendering engine. ### `toString()` **Description**: Get a human readable representation of the detected rendering engine. ``` -------------------------------- ### Access Engine Information Directly Source: https://github.com/whichbrowser/parser-javascript/blob/master/README.md Access the rendering engine's name directly from the result object. ```javascript result.engine.toString(); // Blink ``` -------------------------------- ### Access Browser Name Directly Source: https://github.com/whichbrowser/parser-javascript/blob/master/README.md Access the browser's name property directly. ```javascript result.browser.name; // Chrome ``` -------------------------------- ### Disable Bot Detection Source: https://github.com/whichbrowser/parser-javascript/blob/master/README.md Pass `{ detectBots: false }` to disable bot detection. This allows bots to mimic user agents, useful for serving specific website variants. ```javascript result = new WhichBrowser(request.headers, { detectBots: false }); ``` -------------------------------- ### Set Cache Check Interval Source: https://github.com/whichbrowser/parser-javascript/blob/master/README.md Adjust the cache validity check frequency using `cacheCheckInterval`. This property must be at least 1. Changing this impacts all cached records. ```javascript const result = new WhichBrowser(request.header, { cache: WhichBrowser.SIMPLE_CACHE, cacheExpires: 300, cacheCheckInterval: 1, }); ``` -------------------------------- ### Check if Result is Cached Source: https://github.com/whichbrowser/parser-javascript/blob/master/README.md Check the `cached` property on the result object to determine if it was retrieved from the cache or parsed for the first time. ```javascript if (result.cached) { // from cache } else { // just parsed for the first time } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.