CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-mobile-detect

Device detection library that analyzes User-Agent strings to identify mobile devices, tablets, phones, operating systems, browsers, and device capabilities

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

system-information.mddocs/

System Information

Extract detailed information about operating systems, browsers, and User-Agent characteristics from device strings.

Capabilities

User Agent Detection

Identifies the primary browser or application from the User-Agent string.

/**
 * Returns the (first) detected user-agent string or null
 * @returns The primary detected browser/application name or null
 */
userAgent(): string | null;

Detected User Agents:

  • Browsers: Chrome, Firefox, Safari, Edge, Opera, IE
  • Mobile Browsers: Opera Mini, Opera Mobi, UCBrowser, MQQBrowser, SamsungBrowser
  • Applications: MicroMessenger (WeChat), baiduboxapp, baidubrowser
  • Engines: Webkit, Gecko, Trident, Presto
  • Other: Coast, Dolfin, Fennec, NetFront, NokiaBrowser, Skyfire, Tizen

Usage Examples:

const MobileDetect = require('mobile-detect');

// Chrome detection
const chromeMd = new MobileDetect('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36');
console.log(chromeMd.userAgent()); // 'Chrome'

// Safari on iPhone
const safariMd = new MobileDetect('Mozilla/5.0 (iPhone; CPU iPhone OS 14_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.1 Mobile/15E148 Safari/604.1');
console.log(safariMd.userAgent()); // 'Safari'

// Firefox
const firefoxMd = new MobileDetect('Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0');
console.log(firefoxMd.userAgent()); // 'Firefox'

Multiple User Agents Detection

Returns all detected user-agent identifiers from the User-Agent string.

/**
 * Returns all detected user-agent strings
 * @returns Array of all detected browser/application names
 */
userAgents(): string[];

Usage Examples:

// Complex User-Agent with multiple identifiers
const complexMd = new MobileDetect('Mozilla/5.0 (Linux; Android 11; SM-G991B) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.120 Mobile Safari/537.36');

console.log(complexMd.userAgent());  // 'Chrome' (first detected)
console.log(complexMd.userAgents()); // ['Chrome', 'Safari', 'Webkit'] (all detected)

// Simple case
const simpleMd = new MobileDetect('Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0');
console.log(simpleMd.userAgents()); // ['Firefox', 'Gecko']

Operating System Detection

Identifies the operating system from the User-Agent string.

/**
 * Returns the detected operating system string or null
 * @returns The operating system name or null if not detected
 */
os(): string | null;

Detected Operating Systems:

  • Mobile: iOS, AndroidOS, BlackBerryOS, webOS, Sailfish
  • Desktop: Windows NT, Mac OS X, Linux
  • Other: Symbian, Windows Phone OS, Windows Phone, Windows CE, BREW, Java

Usage Examples:

// iOS detection
const iosMd = new MobileDetect('Mozilla/5.0 (iPhone; CPU iPhone OS 14_6 like Mac OS X)');
console.log(iosMd.os()); // 'iOS'

// Android detection  
const androidMd = new MobileDetect('Mozilla/5.0 (Linux; Android 11; SM-G991B)');
console.log(androidMd.os()); // 'AndroidOS'

// Windows detection
const windowsMd = new MobileDetect('Mozilla/5.0 (Windows NT 10.0; Win64; x64)');
console.log(windowsMd.os()); // 'Windows NT'

// macOS detection
const macMd = new MobileDetect('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)');
console.log(macMd.os()); // 'Mac OS X'

System Categories

Mobile Operating Systems

  • iOS: iPhone, iPad, iPod touch operating system
  • AndroidOS: Google Android in all variants
  • BlackBerryOS: BlackBerry devices
  • webOS: Palm/HP webOS, LG webOS
  • Sailfish: Sailfish OS
  • Windows Phone: Microsoft mobile OS variants
  • Symbian: Nokia Symbian OS

Desktop Operating Systems

  • Windows NT: All modern Windows versions (7, 8, 10, 11)
  • Mac OS X: macOS in all versions
  • Linux: Various Linux distributions

Browser Engines

  • Webkit: Safari, Chrome, many mobile browsers
  • Gecko: Firefox and Mozilla-based browsers
  • Trident: Internet Explorer
  • Presto: Older Opera versions
  • Blink: Chrome, newer Opera (detected as Webkit)

Implementation Notes

  • Pattern Matching: Uses regex patterns to identify system components
  • Caching: Results are cached per instance for performance
  • Priority: Returns first match for userAgent(), all matches for userAgents()
  • Case Insensitive: Detection is case-insensitive
  • Version Support: Use version() and versionStr() methods for version information
  • Fallback: Returns null when no pattern matches

Common Use Cases

const md = new MobileDetect(navigator.userAgent);

// Feature detection based on OS
if (md.os() === 'iOS') {
  // iOS-specific functionality
} else if (md.os() === 'AndroidOS') {
  // Android-specific functionality
}

// Browser-specific optimizations
if (md.userAgent() === 'Safari') {
  // Safari-specific code
} else if (md.userAgent() === 'Chrome') {
  // Chrome-specific code
}

// Multiple browser support check
const agents = md.userAgents();
if (agents.includes('Webkit')) {
  // Webkit-based browser functionality
}

docs

device-detection.md

index.md

system-information.md

version-testing.md

tile.json