Skip to content
Library design

User-Agent Parsing Is Heuristic. I Designed the API to Admit It

User-Agent parsing is a guess that anyone can spoof. client-parser combines User-Agent and Client Hints into one typed result, and its API says plainly that the result is for analytics, not decisions.

Get client-parser on npm
2 min read0 comments
Website

Every User-Agent parser is guessing

Analytics and diagnostics need a normalised view of which browser, OS, device or bot made a request. The raw material is a User-Agent string that any client can change, plus Client Hints whose availability varies and may be restricted for privacy.

Many parsers are heavy, and many APIs quietly encourage using the result for things it cannot support, such as gating features or making security decisions.

A User-Agent string is a claim, not a fact.

The API states its own limits

client-parser documents its heuristic boundary as part of the API. Results are suitable for analytics and presentation. For behaviour, the documentation points to feature detection, and for authentication, authorisation or capability decisions it says not to use the result at all.

That is not a disclaimer buried at the bottom. It shapes how the library is meant to be called.

Two signals, one normalised result

The library combines User-Agent parsing and Client Hints into one typed output covering browser, OS, device, mobile and bot classification, so consumers do not juggle two inconsistent sources.

It has zero dependencies and stays pre-1.0 on purpose. Parsing rules change as clients change, so the project relies on a maintained corpus of representative regression tests and careful changelog review rather than promising stability it cannot guarantee yet.

A playground that never sends your input anywhere

An interactive playground lets you paste any client string and inspect the classification. It runs the library locally in the page, with no server parser, so experimenting with real headers does not send them anywhere.

The broader lesson for API design: when your output is uncertain, put the uncertainty into the contract. Users will build on whatever you imply.

Working through a similar challenge?

Share your context, constraints, and timeline to start a focused conversation.