User Agent Parser
Parse user agent strings to extract browser, operating system, device, and engine information. Perfect for analytics, debugging, and understanding client environments.
What is a User Agent?
A User Agent (UA) is a string that web browsers and other client applications send to web servers to identify themselves. It contains information about the browser, operating system, device type, and rendering engine. This information helps servers deliver optimized content for different platforms.
Why Parse User Agents?
Common Use Cases:
- Analytics: Track browser and OS usage statistics
- Feature Detection: Determine browser capabilities
- Content Optimization: Serve device-specific content
- Security: Identify bots and suspicious traffic
- Debugging: Troubleshoot browser-specific issues
- A/B Testing: Target specific platforms for testing
User Agent Structure
A typical user agent string contains several components:
Mozilla/5.0 (Platform) AppleWebKit/Version (KHTML, like Gecko) Browser/Version Safari/Version
Key Components:
- Mozilla/5.0: Historical compatibility token (legacy from Netscape)
- Platform: Operating system and device information
- Rendering Engine: AppleWebKit, Gecko, Blink, etc.
- Browser: Chrome, Firefox, Safari, Edge, etc.
- Version Numbers: Browser and engine versions
Common Patterns
Desktop Browsers
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
Firefox on macOS:
Mozilla/5.0 (Macintosh; Intel Mac OS X 14.1; rv:120.0)
Gecko/20100101 Firefox/120.0
Safari on macOS:
Mozilla/5.0 (Macintosh; Intel Mac OS X 14_1) AppleWebKit/605.1.15
(KHTML, like Gecko) Version/17.1 Safari/605.1.15
Mobile Browsers
Safari on iPhone:
Mozilla/5.0 (iPhone; CPU iPhone OS 17_1 like Mac OS X)
AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.1 Mobile/15E148 Safari/604.1
Chrome on Android:
Mozilla/5.0 (Linux; Android 14; Pixel 8) AppleWebKit/537.36
(KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36
Operating Systems Detection
Windows
- Windows 11:
Windows NT 10.0(Build 22000+) - Windows 10:
Windows NT 10.0 - Windows 8.1:
Windows NT 6.3 - Windows 7:
Windows NT 6.1
macOS
- Format:
Macintosh; Intel Mac OS X 14_1 - Underscore-separated version (e.g., 14_1 = macOS 14.1)
Linux
- Ubuntu:
X11; Ubuntu; Linux x86_64 - Fedora:
X11; Fedora; Linux x86_64 - Generic:
X11; Linux x86_64
Mobile OS
- iOS:
iPhone; CPU iPhone OS 17_1 - Android:
Linux; Android 14
Browser Detection
Major Browsers:
- Chrome/Chromium: Contains "Chrome/VERSION"
- Firefox: Contains "Firefox/VERSION"
- Safari: Contains "Safari/VERSION" and "Version/VERSION"
- Edge: Contains "Edg/VERSION" (modern) or "Edge/VERSION" (legacy)
- Opera: Contains "OPR/VERSION" or "Opera/VERSION"
Device Type Detection
- Mobile: Contains "Mobile" or "Android"
- Tablet: Contains "Tablet" or "iPad"
- Desktop: Absence of mobile indicators
- Bot/Crawler: Contains "bot", "crawler", "spider", etc.
Important Considerations
Reliability Issues:
- User agents can be spoofed or modified
- Not all information may be accurate
- Some browsers may use privacy settings that limit UA details
- Feature detection is often more reliable than UA parsing
Best Practices:
- Use UA parsing for analytics, not for feature detection
- Combine with other detection methods when possible
- Keep UA parsing libraries updated
- Don't rely solely on UA for critical functionality
- Consider privacy implications
Client Hints
Modern browsers are moving toward User-Agent Client Hints (UA-CH), a new standard that provides more structured UA information while enhancing privacy. Client Hints send data via HTTP headers rather than the UA string.
Privacy & User-Agent Reduction
Browsers are gradually reducing the information in UA strings to protect user privacy:
- Chrome: Implementing UA reduction (freezing minor versions)
- Safari: Already limits detailed version information
- Firefox: Considering similar privacy measures
This trend makes UA parsing less reliable over time, emphasizing the importance of feature detection over UA sniffing.