Lightweight browser detector for parsing user agent strings to extract browser, OS, platform, and engine information
npx @tessl/cli install tessl/npm-bowser@2.12.0Bowser is a lightweight browser detector library for both browser and Node.js environments. It provides a rich API for parsing user agent strings to extract detailed information about browsers, operating systems, platforms, and rendering engines with optimized performance and comprehensive browser support.
npm install bowserconst Bowser = require("bowser");For ES6/TypeScript:
import * as Bowser from "bowser";
// or with --esModuleInterop enabled
import Bowser from "bowser";const Bowser = require("bowser");
// Quick parse - get all information at once
const result = Bowser.parse(window.navigator.userAgent);
console.log(result);
// {
// browser: { name: "Chrome", version: "91.0.4472.124" },
// os: { name: "macOS", version: "10.15.7", versionName: "Catalina" },
// platform: { type: "desktop" },
// engine: { name: "Blink", version: "91.0.4472.124" }
// }
// Create parser for advanced usage
const parser = Bowser.getParser(window.navigator.userAgent);
console.log(`Browser: ${parser.getBrowserName()}`);
console.log(`Version: ${parser.getBrowserVersion()}`);
// Check browser compatibility
if (parser.satisfies({ chrome: ">=60", firefox: ">=55" })) {
console.log("Browser is supported");
}Bowser is built around several key components:
getParser() and parse() for creating parser instancesCore entry points for creating parser instances and getting parsed results directly.
class Bowser {
static getParser(UA: string, skipParsing?: boolean): Parser;
static parse(UA: string): ParsedResult;
static get BROWSER_MAP(): Record<string, string>;
static get ENGINE_MAP(): Record<string, string>;
static get OS_MAP(): Record<string, string>;
static get PLATFORMS_MAP(): Record<string, string>;
}Methods for extracting and working with browser information from user agent strings.
interface Parser {
getBrowser(): BrowserDetails;
getBrowserName(toLowerCase?: boolean): string;
getBrowserVersion(): string | undefined;
isBrowser(browserName: string, includingAlias?: boolean): boolean;
parseBrowser(): BrowserDetails;
}Methods for extracting OS information including version names for Windows, macOS, and Android.
interface Parser {
getOS(): OSDetails;
getOSName(toLowerCase?: boolean): string;
getOSVersion(): string;
isOS(osName: string): boolean;
parseOS(): OSDetails;
}Methods for identifying device platform types including desktop, mobile, tablet, and TV.
interface Parser {
getPlatform(): PlatformDetails;
getPlatformType(toLowerCase?: boolean): string;
isPlatform(platformType: string): boolean;
parsePlatform(): PlatformDetails;
}Methods for identifying browser rendering engines like Blink, WebKit, Gecko, and Trident.
interface Parser {
getEngine(): EngineDetails;
getEngineName(toLowerCase?: boolean): string;
isEngine(engineName: string): boolean;
parseEngine(): EngineDetails;
}Advanced comparison methods for checking browser versions and compatibility requirements.
interface Parser {
compareVersion(version: string): boolean | undefined;
satisfies(checkTree: checkTree): boolean | undefined;
is(anything: string, includingAlias?: boolean): boolean;
some(anythings: string[]): boolean | undefined;
}Essential utility methods for accessing raw user agent strings, testing patterns, and getting complete results.
interface Parser {
getUA(): string;
test(regex: RegExp): boolean;
getResult(): ParsedResult;
parse(): Parser;
}interface ParsedResult {
browser: BrowserDetails;
os: OSDetails;
platform: PlatformDetails;
engine: EngineDetails;
}
interface BrowserDetails {
name?: string;
version?: string;
}
interface OSDetails {
name?: string;
version?: string;
versionName?: string;
}
interface PlatformDetails {
type?: string;
vendor?: string;
model?: string;
}
interface EngineDetails {
name?: string;
version?: string;
}
interface checkTree {
[key: string]: any;
}