User Agent Parser — Complete Guide
What Is a User Agent String?
A user agent (UA) string is a short text header that your browser sends to every web server with each request. It identifies the browser, its version, the operating system, and often the device type. Think of it as the digital ID card your browser flashes every time it loads a page — servers read it to tailor what they send back.
A typical desktop Chrome UA looks like this:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36
(KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36
Anatomy of a User Agent String
That long string is not random — every token has a job:
- Mozilla/5.0 — a legacy compatibility marker. Nearly every browser starts with it, even Firefox and Chrome, for historical reasons.
- (Windows NT 10.0; Win64; x64) — the operating system and architecture in parentheses.
- AppleWebKit/537.36 (KHTML, like Gecko) — the rendering engine the browser is built on (Blink, in Chrome's case, which forked from WebKit).
- Chrome/126.0.0.0 — the actual browser and its version. This is the field parsers care about most.
- Safari/537.36 — a compatibility token that mirrors the WebKit version, not a claim that Safari is running.
Mobile UAs add more clues: Mobile, Android, or iPhone tokens let you distinguish a phone from a desktop without any other signal.
Common User Agent Examples
Recognizing UAs by sight gets easier with practice. Here are a few recognizable patterns:
- Desktop Chrome —
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36 - Desktop Firefox —
Mozilla/5.0 (X11; Linux x86_64; rv:127.0) Gecko/20100101 Firefox/127.0 - iPhone Safari —
Mozilla/5.0 (iPhone; CPU iPhone OS 17_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.5 Mobile/15E148 Safari/604.1 - Android Chrome —
Mozilla/5.0 (Linux; Android 14; Pixel 8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Mobile Safari/537.36 - Googlebot (crawler) —
Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)
Notice the pattern: the platform sits in parentheses, the engine follows, and the browser identity comes last. Spoofed UAs are usually easy to spot because the pieces don't match — a "Chrome" UA claiming a version that doesn't exist, for example.
Why Parsing User Agents Matters
Server-side UA parsing powers three common features:
- Analytics — browser and OS breakdowns tell you which platforms your visitors actually use, so you can prioritize testing and support.
- Responsive delivery — some sites serve different HTML, image sizes, or download links (like an app-store badge) based on the detected device type.
- Bot detection — headless browsers, scrapers, and search-engine crawlers send recognizable UA patterns. Blocking or rate-limiting those patterns is a cheap first line of defense.
Note the word "first" — UA strings are hints, not proof. They are trivially spoofable with a single browser extension or curl -A, so never use them alone for security decisions.
Parsing User Agents in Code
You can read your own UA in any browser console right now:
// Browser: read your own UA
const ua = navigator.userAgent;
console.log(ua);
// Quick checks with regex
const isChrome = /Chrome\/\d+/.test(ua) && !/Edg\//.test(ua);
const isFirefox = /Firefox\/\d+/.test(ua);
const isMobile = /Mobi|Android/i.test(ua);
On the server (Node.js), the UA arrives in the request headers:
const http = require('http');
http.createServer((req, res) => {
console.log(req.headers['user-agent']);
res.end('UA logged');
}).listen(3000);
For production parsing, don't hand-roll regexes — use a maintained library like ua-parser-js (JavaScript) or user-agents (Python). They handle edge cases, new browser versions, and the constant format drift that breaks naive patterns.
Limitations and Privacy
UA parsing has real limits. Strings are spoofable, browsers change format over time (Chrome 110+ sends a reduced UA by default), and some privacy browsers randomize them entirely. Insecure parsers that blindly trust the string are a classic source of analytics garbage — one malformed UA can pollute your dashboards.
There's also a privacy angle: combined with other headers, a UA contributes to browser fingerprinting, letting sites identify users without cookies. Modern browsers have started trimming UA detail and moving to the structured User-Agent Client Hints API, which lets sites request specific fields instead of receiving everything.
Try It Live
Paste any UA string into our free User Agent Parser to instantly see the browser, version, OS, and device — or grab your own browser's UA with one click. No sign-up, no data stored.
FAQ
Why do all user agents start with "Mozilla/5.0"?
It's a compatibility relic from the 1990s browser wars. Sites served modern pages only to Netscape (codenamed Mozilla), so other browsers added the prefix to avoid being served basic HTML — and it stuck.
Can a user agent string be faked?
Yes, trivially. Any HTTP client can send a custom User-Agent header — curl -A "Googlebot" is all it takes. Treat UA-based bot detection as a filter, never as a security boundary.
Is a mobile UA different from a desktop one?
Usually. Mobile UAs contain tokens like Mobile, Android, or iPhone, and may report a different WebKit version. Parsing those tokens is how sites decide which layout or download link to serve.