Lightweight browser detector for parsing user agent strings to extract browser, OS, platform, and engine information
93
Evaluation — 93%
↑ 1.63xAgent success when using this tile
Methods for extracting OS information including version names for Windows, macOS, and Android from user agent strings.
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"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()); // ""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"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");
}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)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
}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");
}
}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");
}
}interface OSDetails {
name?: string;
version?: string;
versionName?: string;
}Install with Tessl CLI
npx tessl i tessl/npm-bowserdocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10