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

os-detection.mddocs/

Operating System Detection

Methods for extracting OS information including version names for Windows, macOS, and Android from user agent strings.

Capabilities

Get OS

Returns complete operating system information including name, version, and version name.

/**
 * Get OS
 * @returns OS details with name, version, and version name
 */
getOS(): OSDetails;

Usage Examples:

const parser = Bowser.getParser(window.navigator.userAgent);

const os = parser.getOS();
console.log(os);
// { name: "macOS", version: "10.15.7", versionName: "Catalina" }

console.log(os.name); // "macOS"
console.log(os.version); // "10.15.7"
console.log(os.versionName); // "Catalina"

Get OS Name

Returns the operating system name with optional case conversion.

/**
 * Get OS name
 * @param toLowerCase - Return lower-cased value
 * @returns Name of the OS — macOS, Windows, Linux, etc.
 */
getOSName(toLowerCase?: boolean): string;

Usage Examples:

const parser = Bowser.getParser(window.navigator.userAgent);

console.log(parser.getOSName()); // "macOS"
console.log(parser.getOSName(true)); // "macos"
console.log(parser.getOSName(false)); // "macOS"

// Handle unknown OS
const unknownParser = Bowser.getParser("Unknown/1.0");
console.log(unknownParser.getOSName()); // ""

Get OS Version

Returns the operating system version string.

/**
 * Get OS version
 * @returns Full version with dots ('10.11.12', '5.6', etc)
 */
getOSVersion(): string;

Usage Examples:

const parser = Bowser.getParser(window.navigator.userAgent);

console.log(parser.getOSVersion()); // "10.15.7"

// Different OS version formats
// macOS: "10.15.7"
// Windows: "NT 10.0"
// Android: "9"
// iOS: "13.5.1"

Is OS

Checks if the current operating system matches a specific OS name.

/**
 * Check if the OS name equals the passed string
 * @param osName - The string to compare with the OS name
 * @returns Boolean indicating if the OS matches
 */
isOS(osName: string): boolean;

Usage Examples:

const parser = Bowser.getParser(window.navigator.userAgent);

// Basic OS checking (case-insensitive)
console.log(parser.isOS("macOS")); // true (if macOS)
console.log(parser.isOS("macos")); // true (case-insensitive)
console.log(parser.isOS("Windows")); // false (if macOS)

// Conditional logic
if (parser.isOS("Windows")) {
  console.log("Windows-specific behavior");
} else if (parser.isOS("macOS")) {
  console.log("macOS-specific behavior");
} else if (parser.isOS("Linux")) {
  console.log("Linux-specific behavior");
}

Parse OS

Explicitly parses and returns operating system information, useful when using lazy parsing.

/**
 * Parse OS and save it to this.parsedResult.os
 * @returns OS details with name, version, and version name
 */
parseOS(): OSDetails;

Usage Examples:

// With lazy parsing
const parser = Bowser.getParser(window.navigator.userAgent, true);

// Force OS parsing
const os = parser.parseOS();
console.log(os); // { name: "macOS", version: "10.15.7", versionName: "Catalina" }

// Subsequent calls return cached result
const sameOS = parser.parseOS();
console.log(sameOS === os); // false (new object, same data)

Common Patterns

OS-specific Feature Detection

const parser = Bowser.getParser(window.navigator.userAgent);

// Mobile OS detection
if (parser.isOS("iOS") || parser.isOS("Android")) {
  console.log("Mobile OS detected");
  // Enable touch-specific features
}

// Desktop OS detection
if (parser.isOS("Windows") || parser.isOS("macOS") || parser.isOS("Linux")) {
  console.log("Desktop OS detected");
  // Enable keyboard shortcuts
}

Version-aware OS Features

const parser = Bowser.getParser(window.navigator.userAgent);
const os = parser.getOS();

if (parser.isOS("macOS") && os.versionName) {
  console.log(`Running on macOS ${os.versionName}`);
  
  // macOS version-specific features
  if (os.versionName === "Big Sur" || os.versionName === "Monterey") {
    console.log("Modern macOS features available");
  }
}

if (parser.isOS("Android") && os.version) {
  const majorVersion = parseInt(os.version);
  if (majorVersion >= 8) {
    console.log("Modern Android features available");
  }
}

Windows Version Detection

const parser = Bowser.getParser(window.navigator.userAgent);
const os = parser.getOS();

if (parser.isOS("Windows")) {
  console.log(`Windows version: ${os.version}`);
  
  // Windows versions:
  // "NT 10.0" = Windows 10/11
  // "NT 6.3" = Windows 8.1
  // "NT 6.1" = Windows 7
  
  if (os.version === "NT 10.0") {
    console.log("Windows 10 or 11");
  }
}

Types

interface OSDetails {
  name?: string;
  version?: string;
  versionName?: string;
}

Supported Operating Systems

Desktop

  • Windows: Windows 7, 8, 8.1, 10, 11
  • macOS: All versions with codenames (Leopard through Monterey and beyond)
  • Linux: Generic Linux detection
  • Chrome OS: Chromebook support

Mobile

  • iOS: iPhone and iPad
  • Android: All versions with codenames (Cupcake through Pie and beyond)
  • Windows Phone: Legacy mobile Windows

Others

  • WebOS: Smart TV and embedded systems
  • BlackBerry: Legacy BlackBerry devices
  • Bada: Samsung Bada OS
  • Tizen: Samsung Tizen OS