User-Agent Header Parser
Parse HTTP User-Agent strings into browser, operating system, device category, and bot / search engine crawler status.
Unlike conventional calculator sites that send your financial numbers, payload data, or code snippets across remote web servers, Affi-Chain processes all mathematical derivations, algorithms, and data parsing 100% locally within your browser sandbox. No tracking cookies, no server-side retention, and zero transmission lag.
What is an HTTP User-Agent Header?
An HTTP User-Agent Parser is a network diagnostics and client analytics tool that evaluates, decodes, and decomposes raw User-Agent request header strings into structured metadata. Standardized under IETF RFC 9110 (HTTP Semantics), the User-Agent header is transmitted by web browsers, mobile applications, search engine web crawlers, API SDKs, and automated bots whenever an HTTP/HTTPS network request is dispatched to a server.
The User-Agent header informs the destination web server about:
- Client Application / Browser Family: Google Chrome, Mozilla Firefox, Apple Safari, Microsoft Edge, Opera.
- Rendering Engine: Blink (Chromium), Gecko (Firefox), WebKit (Safari).
- Host Operating System & Architecture: macOS, Windows 10/11, Linux x86_64, iOS, Android.
- Device Form Factor: Desktop workstation, tablet, mobile smartphone, Smart TV, or automated crawler.
- Crawler Identity: Googlebot, Bingbot, Discordbot, Twitterbot, Applebot.
However, raw User-Agent strings are famously convoluted, redundant, and historical artifacts. Because 1990s web servers used crude browser-sniffing scripts to restrict advanced features solely to Netscape Navigator, every subsequent browser (Internet Explorer, Safari, Chrome) prepended Netscape's compatibility string (Mozilla/5.0) and rival engine names into their own headers—a legacy known as the "User-Agent Lie."
The Affi-Chain User-Agent Parser deconstructs complex header strings instantly in your browser, extracting clean, structured browser families, OS version numbers, device classifications, and bot tags with zero telemetry.
Anatomy of a Canonical Modern User-Agent String
Consider a modern desktop Google Chrome request string:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36
Deconstructing its five distinct structural tokens:
| Token Segment | Historical / Technical Meaning | True Inferred Metadata |
|---|---|---|
Mozilla/5.0 | Netscape 5.0 compatibility claim (Standard on all modern browsers) | Generic modern browser baseline |
(Macintosh; Intel Mac OS X 10_15_7) | System information context | Operating System: macOS Catalina+ (Intel/Apple Silicon) |
AppleWebKit/537.36 | Original Safari rendering engine created by Apple | Base vector engine for both Safari and Blink (Chromium) |
(KHTML, like Gecko) | Konqueror / Mozilla Firefox compatibility claim | Historical engine compatibility flag |
Chrome/130.0.0.0 | Primary application and major release version | Primary Browser: Google Chrome v130 |
Safari/537.36 | Historical claim that browser is "like Safari" | Present in all Chromium-based user agents |
Search Engine & Social Media Web Crawler Directory
Web servers and firewalls routinely parse User-Agents to identify and permit legitimate search engine indexers while blocking malicious scrapers:
| Bot / Crawler Name | User-Agent Identifier Signature | Organization / Purpose |
|---|---|---|
| Googlebot Desktop | Mozilla/5.0 ... (compatible; Googlebot/2.1; +http://www.google.com/bot.html) | Google Search indexing engine |
| Googlebot Mobile | Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X...) AppleWebKit/... Chrome/... Mobile Safari/... (compatible; Googlebot/2.1...) | Mobile-first search index validation |
| Bingbot | Mozilla/5.0 ... (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm) | Microsoft Bing search engine indexer |
| Applebot | Mozilla/5.0 ... (Macintosh; Intel Mac OS X...) AppleWebKit/... (compatible; Applebot/0.1...) | Apple Siri, Spotlight, and Safari Suggestions |
| Twitterbot | Twitterbot/1.0 | Social card metadata unfurling (twitter:image) |
| Discordbot | Mozilla/5.0 (compatible; Discordbot/2.0; +https://discordapp.com) | Rich embed preview generator for shared URLs |
The Modern Transition: User-Agent Client Hints (UA-CH)
To combat digital fingerprinting and protect end-user privacy, modern web standards (W3C Client Hints) are progressively freezing legacy User-Agent strings. Major browsers now provide frozen OS versions (such as 10_15_7 on all modern macOS releases) and require servers to explicitly request granular device details via Client Hints HTTP Headers:
Sec-CH-UA: Returns browser brand and major version (e.g.,"Chromium";v="130", "Google Chrome";v="130").Sec-CH-UA-Mobile: Returns boolean?0(Desktop) or?1(Mobile).Sec-CH-UA-Platform: Returns host platform (e.g.,"macOS","Windows","Android").
Practical Code Implementation: In-Browser User-Agent Tokenizer
Below is an in-browser JavaScript utility that parses raw User-Agent strings into structured JSON objects:
/**
* In-Browser User-Agent Lexical Parser.
*/
function parseUserAgent(ua) {
if (!ua || typeof ua !== 'string') return {};
const info = {
browser: "Unknown",
version: "Unknown",
os: "Unknown",
device: "Desktop",
isBot: false
};
// 1. Detect Bots & Crawlers
if (/googlebot/i.test(ua)) { info.browser = "Googlebot"; info.isBot = true; info.device = "Bot"; }
else if (/bingbot/i.test(ua)) { info.browser = "Bingbot"; info.isBot = true; info.device = "Bot"; }
else if (/discordbot|twitterbot|whatsapp/i.test(ua)) { info.browser = "Social Crawler"; info.isBot = true; info.device = "Bot"; }
// 2. Detect Operating System
if (/windows nt 10\.0/i.test(ua)) info.os = "Windows 10 / 11";
else if (/windows nt 6\.3/i.test(ua)) info.os = "Windows 8.1";
else if (/macintosh|mac os x/i.test(ua)) {
const macMatch = ua.match(/mac os x (\d+[._]\d+[._]?\d*)/i);
info.os = macMatch ? `macOS ${macMatch[1].replace(/_/g, '.')}` : "macOS";
} else if (/android/i.test(ua)) {
info.os = "Android";
info.device = "Mobile";
} else if (/iphone|ipad|ipod/i.test(ua)) {
info.os = "iOS";
info.device = /ipad/i.test(ua) ? "Tablet" : "Mobile";
} else if (/linux/i.test(ua)) {
info.os = "Linux";
}
// 3. Detect Browser Family & Major Version
if (!info.isBot) {
if (/edg\/([0-9.]+)/i.test(ua)) {
info.browser = "Microsoft Edge";
info.version = ua.match(/edg\/([0-9.]+)/i)[1];
} else if (/chrome\/([0-9.]+)/i.test(ua) && !/edg/i.test(ua)) {
info.browser = "Google Chrome";
info.version = ua.match(/chrome\/([0-9.]+)/i)[1];
} else if (/firefox\/([0-9.]+)/i.test(ua)) {
info.browser = "Mozilla Firefox";
info.version = ua.match(/firefox\/([0-9.]+)/i)[1];
} else if (/version\/([0-9.]+).*safari/i.test(ua)) {
info.browser = "Apple Safari";
info.version = ua.match(/version\/([0-9.]+).*safari/i)[1];
}
}
if (/mobile/i.test(ua) && info.device === "Desktop") {
info.device = "Mobile";
}
return info;
}
// Verification Example:
const sampleUa = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36";
console.log(JSON.stringify(parseUserAgent(sampleUa), null, 2));
Comparison Matrix: Client Identification Methodologies
| Methodology | Reliability | Privacy Preservation | Data Richness | Best Engineering Use Case |
|---|---|---|---|---|
| User-Agent String | Moderate (Easily spoofed) | Low (Subject to freezing) | High (OS, Browser, Engine) | Server analytics, crawler identification |
| Client Hints (UA-CH) | High | High (Permissions-policy bound) | High | Modern Chromium server optimization |
| Feature Detection | Absolute (100% reliable) | High | N/A (Tests capabilities only) | Frontend polyfills ('serviceWorker' in navigator) |
| IP Geolocation | Moderate | Moderate | Geographic only | Regional localization, currency selection |
Critical Edge Cases & Common Pitfalls
1. The Security Fallacy of User-Agent Authentication
A fatal cybersecurity flaw is relying on the User-Agent header for access control or security authorization (e.g. if (ua.includes("CompanyApp")) allowAccess()).
- Any HTTP client—including
curl, Postman, Pythonrequests, or browser extension tools—can forge an arbitrary User-Agent header in a single line of code (curl -A "Mozilla/5.0" ...). - Universal Rule: Never use the User-Agent header as an authorization or authentication credential.
2. iPad Desktop-Mode Discrepancy
Since iPadOS 13, Apple iPads request desktop versions of websites by default. Consequently, an iPad sends an identical User-Agent string to a desktop Mac (Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)...).
- To reliably differentiate iPads from desktop Macs in client-side JavaScript, inspect touch capabilities:
const isIPad = navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1;