User Agent Parser: how it works and how to build one
See the browser, OS and device behind a user-agent string. This guide explains what happens behind the button and shows the code, so you can build your own.
What it does
Paste a user-agent string from your logs, or use your own, to see the browser and version, operating system, device type and rendering engine. Bots like Googlebot are detected too.
When to use it
- Reading server logs
- Analytics
- Debugging device-specific bugs
How to use it
- Your own user agent is filled in.
- Paste another one from your logs.
- Read the details.
Try it free in your browser, nothing is uploaded: https://eskillsfy.com/tools/user-agent-parser
How it works
A user-agent string lists the browser, engine and OS in a historic, messy format: almost every browser claims to be ‘Mozilla’ and Chrome also says ‘Safari’. Parsers test specific tokens in a careful order (Edge before Chrome before Safari) because the strings overlap.
Browsers now send less detail (User-Agent reduction), so modern code should prefer feature detection and the User-Agent Client Hints API.
Build it yourself
Here is the core of the tool. It has no dependencies unless noted, so you can paste it into any TypeScript or JavaScript project.
ua.ts (ts)
const BROWSERS: [string, RegExp][] = [
["Edge", /Edg\/([\d.]+)/], ["Opera", /OPR\/([\d.]+)/], ["Samsung Internet", /SamsungBrowser\/([\d.]+)/],
["Firefox", /Firefox\/([\d.]+)/], ["Chrome", /Chrome\/([\d.]+)/], ["Safari", /Version\/([\d.]+).*Safari/],
];
export function parseUa(ua: string) {
const hit = BROWSERS.find(([, re]) => re.test(ua));
const os = /Windows NT/.test(ua) ? "Windows" : /Android/.test(ua) ? "Android" : /iPhone|iPad/.test(ua) ? "iOS" : /Mac OS X/.test(ua) ? "macOS" : /Linux/.test(ua) ? "Linux" : "Unknown";
return { browser: hit?.[0] ?? "Unknown", version: hit ? ua.match(hit[1])![1] : "", os, mobile: /Mobi/.test(ua) };
}
Make it production-ready
- Use navigator.userAgentData where available.
- Detect bots and crawlers.
Questions
Is it 100% accurate?
User agents can be faked and browsers now reduce the detail they send, so treat it as a good guess.
Free, runs in your browser, nothing is uploaded.