Skip to content
🛠️ToolsShed

User Agent Parser

Parse any User-Agent string to extract browser, OS, device type, and engine details.

About this tool

A User-Agent string is the technical fingerprint that every web browser and application sends to servers when accessing the internet. It contains crucial information about your device, operating system, browser type, and rendering engine—data that websites use to optimize their content, detect compatibility, and understand their audience. The User Agent Parser tool instantly decodes these cryptic strings, transforming raw HTTP headers into readable, structured information about browsers, operating systems, device types, and engines.

To use the tool, simply paste any User-Agent string into the input field and click parse. The tool automatically extracts and displays the browser name and version, operating system details, device classification (desktop, mobile, tablet), and the underlying rendering engine (like Webkit, Gecko, or Trident). This is invaluable for web developers debugging cross-browser issues, system administrators auditing server logs, and security professionals analyzing traffic patterns or detecting unusual requests.

One key insight is that User-Agent strings vary widely—older devices may report outdated engines, and some applications intentionally spoof or obfuscate their identifiers. The parser handles standard formats accurately, but always verify results against your own requirements if the detection seems unusual. Understanding your audience's browsers and devices helps optimize performance, ensure compatibility, and diagnose why a web experience works perfectly in Chrome but breaks in Safari.

Frequently Asked Questions

Code Implementation

import re

UA_PATTERNS = {
    "browser": [
        (r"Edge/([d.]+)",           "Edge"),
        (r"OPR/([d.]+)",            "Opera"),
        (r"Chrome/([d.]+)",         "Chrome"),
        (r"Firefox/([d.]+)",        "Firefox"),
        (r"Safari/([d.]+).*Version/([d.]+)", "Safari"),
        (r"MSIE ([d.]+)",           "IE"),
        (r"Trident/.*rv:([d.]+)",   "IE"),
    ],
    "os": [
        (r"Windows NT ([d.]+)",     "Windows"),
        (r"Mac OS X ([d._]+)",      "macOS"),
        (r"Android ([d.]+)",        "Android"),
        (r"iPhone OS ([d_]+)",      "iOS"),
        (r"Linux",                   "Linux"),
    ],
    "device": [
        (r"Mobile",                  "Mobile"),
        (r"Tablet",                  "Tablet"),
        (r"iPad",                    "Tablet"),
        (r"iPhone",                  "Mobile"),
    ],
}

def parse_ua(ua: str) -> dict:
    result = {"browser": "Unknown", "os": "Unknown", "device": "Desktop", "raw": ua}

    for pattern, name in UA_PATTERNS["browser"]:
        m = re.search(pattern, ua)
        if m:
            result["browser"] = f"{name} {m.group(1)}"
            break

    for pattern, name in UA_PATTERNS["os"]:
        m = re.search(pattern, ua)
        if m:
            version = m.group(1).replace("_", ".") if m.lastindex else ""
            result["os"] = f"{name} {version}".strip()
            break

    for pattern, device_type in UA_PATTERNS["device"]:
        if re.search(pattern, ua, re.IGNORECASE):
            result["device"] = device_type
            break

    return result

test_uas = [
    "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/120.0.0.0 Safari/537.36",
    "Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 Mobile/15E148 Safari/604.1",
    "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)",
]

for ua in test_uas:
    info = parse_ua(ua)
    print(f"Browser: {info['browser']}, OS: {info['os']}, Device: {info['device']}")

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.