← All Posts

How to Parse User Agent Strings (Browser, OS, Device)

Published on February 7, 2026

What Is a User Agent?

A user agent is a string that a client (typically a web browser) sends to a web server with every HTTP request. It identifies the application, operating system, vendor, and version of the requesting software. Web servers use this information to serve appropriate content, log analytics data, and detect bots or crawlers.

Every time you visit a website, your browser sends a user agent string in the User-Agent HTTP header. This string has grown increasingly complex over the years due to browser compatibility hacks, making it notoriously difficult to parse manually.

Structure of a User Agent String

A typical modern user agent string looks like this:

Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36

This Chrome user agent contains several sections, each representing a layer of compatibility information. The Mozilla/5.0 prefix is a historical artifact — nearly all browsers include it for compatibility reasons. The parenthesized section contains the operating system and platform details. The remaining tokens identify the rendering engine and browser.

// Breaking down the components:
Mozilla/5.0                          // Compatibility token
(Windows NT 10.0; Win64; x64)       // OS: Windows 10, 64-bit
AppleWebKit/537.36                   // Rendering engine
(KHTML, like Gecko)                  // Engine compatibility
Chrome/120.0.0.0                     // Browser and version
Safari/537.36                        // Safari compatibility token

The reason Chrome includes "Safari/537.36" and "AppleWebKit" is historical — browsers added tokens from other browsers to avoid being blocked by websites that only served content to specific user agents. This layered approach makes user agent strings messy but also makes parsing them a well-understood problem.

Browser Detection

Identifying the browser from a user agent string requires checking for specific tokens in the correct order. Here are some common patterns:

// Chrome (but not Edge, Opera, or Brave)
Mozilla/5.0 ... Chrome/120.0.0.0 Safari/537.36

// Firefox
Mozilla/5.0 ... Gecko/20100101 Firefox/121.0

// Safari (macOS/iOS)
Mozilla/5.0 (Macintosh; ...) AppleWebKit/605.1.15 ... Version/17.2 Safari/605.1.15

// Edge (Chromium-based)
Mozilla/5.0 ... Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0

// Opera
Mozilla/5.0 ... Chrome/120.0.0.0 Safari/537.36 OPR/106.0.0.0

The key challenge is that many browsers are Chromium-based and include Chrome in their user agent. You need to check for browser-specific tokens like Edg/ (Edge), OPR/ (Opera), or Brave before falling back to Chrome.

Bot and Crawler Detection

Search engine crawlers and automated bots also send user agent strings, though theirs are typically more straightforward:

// Googlebot
Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)

// Bingbot
Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)

// GPTBot (OpenAI)
Mozilla/5.0 AppleWebKit/537.36 ... GPTBot/1.0

// Generic scraper
Python-urllib/3.11

Detecting bots is important for security, analytics accuracy, and rate limiting. Legitimate bots typically identify themselves clearly in the user agent string and often include a URL pointing to their documentation. Malicious bots, on the other hand, usually spoof popular browser user agents to avoid detection.

Mobile vs Desktop Detection

User agent strings also reveal whether the request comes from a mobile device, tablet, or desktop. Mobile browsers typically include the keyword "Mobile" in their user agent, along with the device name. For example, an iPhone user agent includes "iPhone" and "Mobile," while an iPad includes "iPad" but no "Mobile" token.

// iPhone Safari
Mozilla/5.0 (iPhone; CPU iPhone OS 17_2 like Mac OS X) AppleWebKit/605.1.15 ... Mobile/15E148 Safari/604.1

// Android Chrome
Mozilla/5.0 (Linux; Android 14; Pixel 8) AppleWebKit/537.36 ... Chrome/120.0.0.0 Mobile Safari/537.36

// iPad Safari
Mozilla/5.0 (iPad; CPU OS 17_2 like Mac OS X) AppleWebKit/605.1.15 ... Safari/604.1

Device detection from user agents is used for responsive content serving, analytics segmentation, and redirecting users to mobile-optimized pages. However, it is worth noting that the industry is moving toward Client Hints as a more structured alternative to user agent strings.

How to Use the User Agent Parser

Open the User Agent Parser and follow these steps:

  1. Paste a user agent string into the input field, or use your current browser's user agent which is auto-detected.
  2. View the parsed results — the tool extracts the browser name, version, operating system, device type, and rendering engine.
  3. Identify bots — the parser flags known crawler and bot user agents.
  4. Test multiple user agents to compare how different browsers and devices identify themselves.

The tool is perfect for debugging analytics discrepancies, testing bot detection logic, and understanding the user agents you see in your server logs. It runs entirely in your browser with no data sent to any server.

Ready to parse user agents? Open User Agent Parser

Need to extract data from websites?

PulpMiner turns any webpage into a structured JSON API. No scraping code needed — just point, click, and get clean data.

Try PulpMiner Free

No credit card required