Skip to main content

Parse a user agent string

A user agent parser reads the tokens in a User-Agent header and turns them into structured fields. Below, three fixed strings — a desktop browser, a phone and a search crawler — run through the same parser as the interactive tool, followed by the rules it applies.

Worked example

Chrome on Windows
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Browser
Chrome 120.0.0.0
Engine
Blink
Operating system
Windows 10/11
Device class
Desktop
Device
Unknown
CPU architecture
x64
Bot / crawler
No
Safari on iPhone
Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Mobile/15E148 Safari/604.1
Browser
Safari 17.0
Engine
WebKit
Operating system
iOS 17.0
Device class
Mobile
Device
Apple iPhone
CPU architecture
Unknown
Bot / crawler
No
Googlebot (smartphone crawler)
Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.6099.216 Mobile Safari/537.36 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)
Browser
Chrome 120.0.6099.216
Engine
Blink
Operating system
Android 6.0.1
Device class
Bot
Device
Nexus 5X Build/MMB29P
CPU architecture
Unknown
Bot / crawler
Googlebot

Chrome on Windows sends Windows NT 10.0, which Windows 10 and Windows 11 share, so the OS is shown as 10/11. On the iPhone, Version/17.0 gives the Safari version and iPhone OS 17_0 gives the iOS version. The Googlebot string embeds a complete Chrome on Android user agent, but crawler signatures are checked first, so the device class is bot; the browser and OS fields still show what the crawler presents itself as.

Key rules

  • Crawler signatures are checked first: Googlebot, Bingbot, DuckDuckBot, YandexBot, Baiduspider, Slackbot, Twitterbot and facebookexternalhit. A match sets the device class to bot even when browser tokens are present.
  • Browsers are matched in a fixed order — Edge (Edg/), Opera (OPR/), Samsung Internet, Firefox, Chrome, Safari, then Chromium — because most strings also contain the tokens of other browsers. The engine follows the browser: Blink, Gecko or WebKit.
  • The operating system comes from the platform section in parentheses: iPhone, iPad, Android, Windows NT, CrOS, Mac OS X or Linux. Underscores in Apple version numbers are converted to dots.
  • The device class is tablet for iPad, a Tablet token, or Android without a Mobile token; mobile for iPhone or Android with a Mobile token; and desktop for Windows, macOS, Linux and ChromeOS.
  • Anything the string does not state stays unknown (null in the JSON output) instead of being guessed. Confidence is high only when both a browser and an operating system were matched.
  • Any client can send a Googlebot user agent. To confirm a real Google crawler, run a reverse DNS lookup on the request IP, check that the name ends in googlebot.com or google.com, then confirm with a forward lookup.

More user agent guides