API Reference
getOS
Returns a single string identifying the current operating system.
import { getOS } from 'os-detect'
const os = getOS()
// 'ios' | 'macos' | 'android' | 'windows' | 'linux' | 'chromeos' | 'unknown'Detection priority (first match wins):
- iOS / iPadOS
- Android
- ChromeOS
- Linux
- macOS
- Windows
'unknown'
ChromeOS is checked before Linux because ChromeOS userAgent strings contain "Linux" — checking in the wrong order would misidentify Chromebooks.
OS type
type OS = 'ios' | 'macos' | 'android' | 'windows' | 'linux' | 'chromeos' | 'unknown'Boolean detection
All functions are synchronous, side-effect-free, and cache their result after the first call.
import {
detectIsIOS,
detectIsMacOS,
detectIsAndroid,
detectIsWindows,
detectIsLinux,
detectIsChromeOS,
} from 'os-detect'| Function | Returns true when | Node.js behaviour |
|---|---|---|
detectIsIOS() | iPhone, iPod, or iPad (including iPadOS 13+) | always false |
detectIsMacOS() | macOS desktop (correctly excludes iPadOS 13+) | process.platform === 'darwin' |
detectIsAndroid() | Android phones and tablets | process.platform === 'android' |
detectIsWindows() | Windows desktop or laptop (32-bit and 64-bit) | process.platform === 'win32' |
detectIsLinux() | Linux desktop (excludes Android and ChromeOS) | process.platform === 'linux' |
detectIsChromeOS() | ChromeOS devices | always false |
iPadOS 13+ note
Since iPadOS 13, Safari reports Macintosh in the userAgent string. detectIsIOS() handles this correctly by checking navigator.maxTouchPoints > 1. detectIsMacOS() excludes iPadOS devices accordingly — you will never get true from both functions on the same device.
Example — conditional rendering
import { detectIsIOS, detectIsAndroid, detectIsWindows } from 'os-detect'
if (detectIsIOS()) {
// show App Store badge
} else if (detectIsAndroid()) {
// show Google Play badge
} else if (detectIsWindows()) {
// show Windows Store badge
}detectIsWindows11
Asynchronous. Returns true only when both detectIsWindows() is true and the Windows 11 check succeeds.
import { detectIsWindows11 } from 'os-detect'
const isWin11 = await detectIsWindows11() // Promise<boolean>Browser — uses navigator.userAgentData.getHighEntropyValues(['platformVersion']) (Chrome 90+ / Edge 90+). Windows 11 reports platformVersion >= 13.0.0. Returns false if the API is unavailable or the call fails.
Node.js — uses os.release(). Windows 11 has build number >= 22000. Returns false if the import fails.
Returns false immediately if detectIsWindows() is false — no async work is done.
// Differentiate Windows 10 from Windows 11
const isWindows = detectIsWindows()
const isWin11 = await detectIsWindows11()
if (isWin11) {
console.log('Windows 11')
} else if (isWindows) {
console.log('Windows 10 or older')
}Device category
Quick coarse checks that group OS values into mobile and desktop buckets.
import { isMobileDevice, isDesktopDevice } from 'os-detect'
isMobileDevice() // true if iOS or Android
isDesktopDevice() // true if macOS, Windows, Linux, or ChromeOSNote:
isMobileDevice()andisDesktopDevice()are not mutually exclusive. A device with an unrecognized OS returnsfalsefor both. There is no overlap on the currently recognised OS values.