kmp-user-agent
One Kotlin Multiplatform library that parses and generates User-Agent strings with the same logic and results on Android, iOS, JVM, and JS -- so you stop hand-rolling UA regex per platform, and stop finding out your detection logic silently diverges on the one platform nobody tested it on.
The proof is below: not a mockup, your own browser, parsed right now by the real, published @lempert/user-agent package. Already sold? Jump straight to Get started.
Why kmp-user-agent
- One shared implementation, four platforms.
UserAgentParser/UserAgentGeneratorrun the exact same detection/generation logic and return the exact same results everywhere -- see Core Concepts for the shared model (the language bindings differ slightly per platform; each platform guide shows the real syntax). React Native isn't a fifth target here -- it's the same JS build as Browser & Node.js, verified separately under Metro and Hermes; see its own guide. - Composable, tree-shakeable type packs. Pull in only the detection categories you need -- browser, engine, OS, device, bots, AI/LLM crawlers. There's no implicit fallback pulling in packs you didn't ask for, so a bundler can tree-shake the rest out of your JS build (verified for webpack/esbuild; React Native's Metro is one known exception).
- Bot and AI-agent detection, on the way.
UserAgentInfoalready carriesbot/aiAgentfields, and the library's source already includesUserAgentBotTypes/UserAgentAIAgentTypespacks recognizing dozens of well-known crawlers and LLM agents -- see the Type Reference for the full current roster and its publish status (not yet in a published release, so the live demo below won't show a match yet even for a real bot's UA string). - Extensible without forking. Add detection for something the built-in packs miss, or override one of their results, via a plain
UserAgentTypePack-- either populate a named field directly, or use the open-endedcustommap for anything that doesn't fit one. - MIT-licensed and actually published. A real npm package backs both demos on this page; the same logic ships to Maven Central for Android/iOS/JVM. See License for the full license and third-party attribution.
Supported platforms
The same shared parsing/generation logic, with a native binding per platform -- pick your guide:
Logos via Simple Icons (CC0-1.0, see License for the full attribution) -- identification only, not an endorsement by, or partnership with, any company shown.
A sample of what it detects
A few of the real browsers, operating systems, bots, and AI agents the library recognizes by name -- see the Type Reference for the complete list. Icons are identification only (see the attribution note at the end), not an endorsement by, or partnership with, any company shown.
Browsers and operating systems -- live in the published 0.2.0 package today:
Windows and Microsoft Edge have no logos here -- notably, Simple Icons (the CC0-licensed icon set these come from) doesn't carry either mark, despite both being extremely common.
Bots -- exist in the library's source since an unreleased 0.3.0, not in the published 0.2.0 package this site installs:
AI agents -- the fuller roster shown below exists only in an also unreleased 0.4.0; same not-yet-published status as bots above:
Meta appears in both rows above on purpose -- it operates both a documented bot (facebookexternalhit) and a separate documented AI-agent crawler (Meta-ExternalAgent), and the library detects them as distinct entries.
Logos via Simple Icons (CC0-1.0, see License for the full attribution) -- each mark remains its respective owner's trademark. Showing a logo here identifies which company's crawler/browser a UA string matches; it does not imply that company endorses or partners with this library.
Parse a User-Agent
Your User-Agent: Detecting your browser…
| Browser | Loading… |
|---|---|
| Engine | Loading… |
| OS | Loading… |
| Device | Loading… |
| Bot | Loading… |
| AI Agent | Loading… |
"Not detected" can mean either that this browser/OS isn't recognized, or that the field isn't covered by the currently published package version.
Generate a User-Agent
Pick browser/engine/OS/device filters and generate a plausible User-Agent string. Leave any filter on "Any (random)" and it's filled in for you.
Generating…
Fields left on "Any (random)" are filled from a known-safe preset; picking both a browser and OS that don't normally pair together (e.g. Firefox + Android) still generates a valid string -- just without the OS detail.
Get started
- Core Concepts -- the shared model and pack-composition pattern, explained once.
- Type Reference -- every name each built-in pack recognizes.
- Browser & Node.js or React Native -- for JavaScript or TypeScript.
- Android or JVM -- for Kotlin.
- iOS -- for Swift.