or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

browser-detection.mdcompatibility-testing.mdengine-detection.mdindex.mdos-detection.mdparser-creation.mdplatform-detection.md
tile.json

tessl/npm-bowser

Lightweight browser detector for parsing user agent strings to extract browser, OS, platform, and engine information

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/bowser@2.12.x

To install, run

npx @tessl/cli install tessl/npm-bowser@2.12.0

index.mddocs/

Bowser

Bowser 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.

Package Information

  • Package Name: bowser
  • Package Type: npm
  • Language: JavaScript with TypeScript definitions
  • Installation: npm install bowser

Core Imports

const Bowser = require("bowser");

For ES6/TypeScript:

import * as Bowser from "bowser";
// or with --esModuleInterop enabled
import Bowser from "bowser";

Basic Usage

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");
}

Architecture

Bowser is built around several key components:

  • Static Factory Methods: getParser() and parse() for creating parser instances
  • Parser Class: Core parsing engine with getter methods for browser, OS, platform, and engine information
  • Comparison Engine: Advanced browser compatibility checking with version range support
  • Constants: Mapping objects for browser names, OS identifiers, platform types, and rendering engines
  • Utilities: Helper functions for version comparison and browser alias resolution

Capabilities

Static Factory Methods

Core 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>;
}

Parser Creation

Browser Detection

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;
}

Browser Detection

Operating System Detection

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;
}

Operating System Detection

Platform Detection

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;
}

Platform Detection

Rendering Engine Detection

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;
}

Rendering Engine Detection

Browser Compatibility Testing

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;
}

Browser Compatibility Testing

Core Utility Methods

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;
}

Parser Creation

Types

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;
}