User Agent Parser — What Your Browser String Reveals
A user agent string tells servers your browser, version, OS, and device type. Here's how to parse one, what each component means, and how servers use this data.
Every HTTP request your browser makes includes a User-Agent header — a string that identifies your browser, version, operating system, and device. Servers use this information for analytics, feature detection, bot filtering, and sometimes to serve different content to different devices.
Use the User Agent Parser to parse any user agent string into its components instantly.
Anatomy of a user agent string
Modern user agent strings are long and historically confused. Here’s 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
Breaking it down:
| Component | Value | Meaning |
|---|---|---|
Mozilla/5.0 | All modern browsers | Historical compatibility token — means nothing about the browser |
(Windows NT 10.0; Win64; x64) | Windows 10/11, 64-bit | Operating system and architecture |
AppleWebKit/537.36 | Blink-based browser | Rendering engine (all Chrome-based browsers report this) |
(KHTML, like Gecko) | Historical | Compatibility token for sites that checked for Gecko |
Chrome/120.0.0.0 | Chrome 120 | Actual browser and version |
Safari/537.36 | All WebKit browsers | Compatibility token — Chrome reports this to not break Safari detection |
The “Mozilla/5.0” at the start has nothing to do with Mozilla Firefox. Every major browser reports it for historical compatibility reasons — some early 1990s sites only served rich content to “Mozilla” browsers (the original Netscape browser). Modern browsers kept the token to avoid being flagged as unsupported.
Common user agent strings
Chrome (Windows)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Firefox (macOS)
Mozilla/5.0 (Macintosh; Intel Mac OS X 14.3; rv:121.0) Gecko/20100101 Firefox/121.0
Safari (iPhone)
Mozilla/5.0 (iPhone; CPU iPhone OS 17_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.2 Mobile/15E148 Safari/604.1
Edge (Windows)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0
Android Chrome
Mozilla/5.0 (Linux; Android 14; Pixel 7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.69.159 Mobile Safari/537.36
Googlebot (Google’s crawler)
Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)
curl
curl/8.4.0
Parsing user agents in code
Python (ua-parser library)
from ua_parser import user_agent_parser
ua_string = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
result = user_agent_parser.Parse(ua_string)
print(result['user_agent']['family']) # 'Chrome'
print(result['user_agent']['major']) # '120'
print(result['os']['family']) # 'Windows'
print(result['os']['major']) # '10'
print(result['device']['family']) # 'Other' (desktop)
print(result['device']['is_mobile']) # False
The ua-parser library uses a regexes.yaml definition file maintained by the community, with regular expressions matching hundreds of known browsers and devices.
JavaScript / Node.js (ua-parser-js)
const UAParser = require('ua-parser-js');
const ua = "Mozilla/5.0 (iPhone; CPU iPhone OS 17_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.2 Mobile/15E148 Safari/604.1";
const parser = new UAParser(ua);
const result = parser.getResult();
console.log(result.browser.name); // 'Mobile Safari'
console.log(result.browser.version); // '17.2'
console.log(result.os.name); // 'iOS'
console.log(result.os.version); // '17.2'
console.log(result.device.type); // 'mobile'
console.log(result.device.vendor); // 'Apple'
console.log(result.device.model); // 'iPhone'
Go (mssola/useragent)
import "github.com/mssola/useragent"
ua := useragent.New("Mozilla/5.0 (Linux; Android 14; Pixel 7) AppleWebKit/537.36...")
name, version := ua.Browser() // "Chrome", "120.0.6099.230"
ua.OS() // "Android"
ua.Mobile() // true
ua.Bot() // false
User agent detection for server-side use cases
Bot detection
Legitimate bots (Googlebot, Bingbot, Twitterbot) identify themselves honestly in their user agents. Malicious bots often:
- Spoof browser user agents to avoid detection
- Use outdated browser versions
- Use inconsistent platform tokens (claiming to be “Windows; ARM” which doesn’t make sense)
Reliable bot detection combines user agent analysis with:
- Rate limiting (many requests per second)
- Behavioral patterns (no mouse movement, no CSS loading)
- IP reputation (datacenter IP ranges, Tor exit nodes)
- Header consistency (bots often send fewer headers or in different order)
For casual bot filtering, checking for known bot patterns in the user agent is fast and handles legitimate crawlers well:
def is_bot(user_agent_string):
bot_patterns = [
r'bot', r'crawl', r'spider', r'slurp', r'scan',
r'curl', r'wget', r'python-requests', r'axios',
r'Googlebot', r'Bingbot', r'DuckDuckBot'
]
pattern = '|'.join(bot_patterns)
return bool(re.search(pattern, user_agent_string, re.IGNORECASE))
Device type detection for analytics
from ua_parser import user_agent_parser
def get_device_category(ua_string):
parsed = user_agent_parser.Parse(ua_string)
device = parsed['device']
if device['family'] == 'Spider':
return 'bot'
elif device.get('brand') in ('Apple', 'Samsung', 'Google') and \
any(m in ua_string for m in ['iPhone', 'iPad', 'Android', 'Pixel']):
if 'iPad' in ua_string or 'Tablet' in ua_string:
return 'tablet'
return 'mobile'
else:
return 'desktop'
Content negotiation
Legacy approach — serve different HTML to mobile browsers. This is mostly obsolete now. Modern practice uses responsive CSS instead.
The one valid remaining use case: serving lighter-weight images or video on mobile. You can check user agent for mobile indicators in server-side code and serve smaller srcset variants. But CSS media queries and the <picture> element solve this client-side without server-side UA detection.
The User-Agent Client Hints API (replacing User-Agent)
The traditional User-Agent header exposes too much information (privacy concern) and is widely spoofed (reliability concern). Google introduced the User-Agent Client Hints API as a replacement.
With UA-CH, the server requests only the specific information it needs:
<!-- Server requests specific hints: -->
Accept-CH: Sec-CH-UA, Sec-CH-UA-Mobile, Sec-CH-UA-Platform
<!-- Browser responds with structured data: -->
Sec-CH-UA: "Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"
Sec-CH-UA-Mobile: ?0
Sec-CH-UA-Platform: "Windows"
The structured format is easier to parse reliably than the User-Agent string. However, it requires an explicit request-response negotiation and is only supported by Chrome-based browsers.
For the foreseeable future, User-Agent header parsing remains necessary for cross-browser analytics.
Reading your own user agent
Your browser sends its user agent with every request. To see it:
- Open the User Agent Parser — it detects your current browser’s user agent automatically
- Or: open browser DevTools → Network tab → any request → Request Headers → User-Agent
- Or: JavaScript:
navigator.userAgent
console.log(navigator.userAgent);
// Current browser's UA string
What user agent data is used for
Analytics: Google Analytics, Plausible, and other tools aggregate user agent data to show browser/OS/device breakdowns. This tells you what your users actually run — important for deciding how much effort to invest in browser compatibility.
A/B testing: some platforms segment test cohorts by device type, using user agent to categorize visitors.
Security: some web application firewalls (WAFs) block requests with user agents associated with vulnerability scanners (Nikto, sqlmap, Burp Suite).
CDN caching: CDNs may include user agent in cache keys to serve different content to mobile vs desktop.
Feature gating: serving polyfills only to browsers that need them, based on browser version detection from user agent.
Related tools
- User Agent Parser — parse any user agent string
- HTTP Status Codes — reference for HTTP response codes
- URL Encoder — encode query parameters in URLs
Related posts
- Bot Detection Using User Agent Strings — Googlebot, Bingbot, and Crawlers — Identify search engine crawlers, social media bots, and malicious scrapers from …
- Browser Detection in JavaScript — Feature Detection vs User Agent Parsing — Detect browsers, OS, and device type in JavaScript using user agent strings, fea…
- User-Agent Client Hints — Modern Browser Detection Without UA Sniffing — User-Agent Client Hints replace UA string parsing with structured HTTP headers. …
Related tool
Parse any User-Agent string into browser, OS, device, and engine. Or detect your own. Built on the maintained ua-parser-js dataset.
Written by Mian Ali Khalid. Part of the Dev Productivity pillar.