Detect macOS browser
Guess whether the device is a Mac, iPhone or iPad from the platform string.
function isApplePlatform() { return /Mac|iPhone|iPad|iPod/.test(navigator.userAgentData?.platform ?? navigator.platform); }
Usage
// Headless Chromium on Linux:
isApplePlatform(); // → false
isApplePlatform(); // e.g. true on a Mac, an iPhone or an iPad
Know the limits
- navigator.platform is deprecated, and iPadOS reports "MacIntel" in desktop mode, so this cannot tell a Mac from an iPad. Chromium’s navigator.userAgentData is read where available.
- Use it for keyboard hints (⌘ versus Ctrl), not for features: detect those directly.
The function above is the code the usage lines run. It does not validate its arguments; add checks where it receives untrusted input.
Source & maintenance
Based on Detect macOS browser from the original 1loc collection by Nguyen Huu Phuoc. Copyright (c) 2020 phuoc-ng. MIT licensed.
Reads navigator.userAgentData where available; platform limits documented. Executed in Chromium. Original MDX retained as inert source evidence.
Maintained by Oveyon. Original source commit: 14b481cf60df. This edition’s file: contents/detect-macos-browser.mdx in akamind/1loc, commit 0a77f131b22d. Read the license.
Keep exploring
- Check if a given DOMRect is contained within another DOMRect — True when the target lies inside the container or on its edges.
- Check if two DOMRects intersect — Two rects intersect when they meet on both axes.
- Compare two DOMRects for size and position match — Compare x, y, width and height exactly.