Device detection library that analyzes User-Agent strings to identify mobile devices, tablets, phones, operating systems, browsers, and device capabilities
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Extract detailed information about operating systems, browsers, and User-Agent characteristics from device strings.
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:
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'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']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:
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'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
}