Frontend Development 4 min read

Understanding User Agent Parsing and Using the ua-device Library

This article explains how User Agent strings reveal operating system, CPU, browser and mobile device details, discusses the challenges of parsing mobile UA strings, introduces Baidu's open‑source ua-device library for accurate detection, and provides testing links for developers.

System Architect Go
System Architect Go
System Architect Go
Understanding User Agent Parsing and Using the ua-device Library

Three weeks ago I built a tool for detecting user information from the User Agent string, and today I share the details as a follow‑up.

When you click a software download page, the site often automatically detects your operating system and offers the appropriate installer; this detection is performed using the User Agent (UA) string, which contains not only OS information but also CPU, browser, and, on mobile devices, phone brand and model.

The UA is simply a text string; you can view it in a browser by entering navigator.userAgent . The format is relatively stable on desktop browsers, making parsing straightforward.

On mobile devices, however, Chinese manufacturers lack a unified standard, and the sheer variety of phone models and custom ROMs means that UA formats differ widely, even for the same brand and model, complicating accurate extraction of brand and model information.

Fortunately, Baidu's front‑end team has open‑sourced a library called ua-device that addresses these mobile UA parsing challenges. The library contains thousands of regular‑expression rules, achieves a high detection rate, and is continuously updated, though it currently requires installation via npm on the backend rather than a simple <script src="..."> inclusion.

Using ua-device is simple: pass the UA string to the library and it returns detailed device information. The official documentation provides an example, illustrated in the image below.

For a quick test, you can visit my demo page, which displays the basic information of the device you are using:

http://oiil9hcbg.bkt.clouddn.com/user-agent.html

You can also call my backend API directly; the request format is shown in the following screenshot.

In today's big‑data era, acquiring accurate user information is the first step for any analysis, and the UA string remains a valuable source when troubleshooting or profiling user behavior.

FrontendMobileuser-agentbrowser detectionua-device
System Architect Go
Written by

System Architect Go

Programming, architecture, application development, message queues, middleware, databases, containerization, big data, image processing, machine learning, AI, personal growth.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.