Expand description
ua — User-Agent generation and browser detection utilities.
This crate helps you build realistic User-Agent strings by detecting installed browsers
and (when possible) using the detected browser version. It is designed for HTTP clients,
automation tools, and apps that need browser-like headers.
§Main API
Most users only need:
build_user_agentto generate a UA string.UaStrictnessto choose between strict vs resilient behavior.
If you want more control, you can use:
platform_infoto inspect the platform token inputs.detect_browsersto list installed browsers.choose_best_browserto override selection logic.
§What it does
- Detects platform information: OS family and CPU architecture.
- Detects installed browsers (best-effort, OS-specific):
- Windows: checks common install paths and reads
.exefile version metadata. - macOS: checks
/Applications/*.appand readsInfo.plistversion metadata. - Linux: checks
PATHbinaries and optionally inspects Flatpak/Snap installs.
- Windows: checks common install paths and reads
- Generates browser-like User-Agent strings for:
- Chromium family: Chrome / Edge / Chromium / Brave / Opera
- Firefox
- Safari (best-effort only)
§Strictness
The UaStrictness mode controls how strict UA generation is:
UaStrictness::Real:- Requires a detected browser and a parseable version.
- Supported for Chromium-family and Firefox.
- Safari is not supported in
Realmode because Safari’s WebKit token mapping is not reliably derivable from the installed version alone.
UaStrictness::BestEffort:- Produces a reasonable UA even when version detection is incomplete.
- Recommended when you need resilience across varied machines.
§Non-goals
- This crate does not attempt full browser fingerprint emulation. For more browser-like behavior, also consider sending UA-CH and Sec-Fetch headers.
§Example
use ua::{build_user_agent, UaStrictness};
let ua = build_user_agent(UaStrictness::BestEffort)?;
println!("{ua}");§Notes on privacy and ethics
Browser-like headers can be used to reduce false blocks in legitimate automation, but also can be used for deceptive fingerprinting. Use responsibly and comply with applicable terms and policies.
Structs§
- Browser
Info - Information about a detected browser installation.
- Platform
Info - Platform information used to build the UA platform token.
- SemVerish
- Parsed “version-like” representation extracted from browser version strings.
Enums§
- Agent
Error - Errors returned by platform/browser detection and UA generation.
- Arch
- CPU architecture classification for UA platform tokens.
- Browser
Kind - Browser families supported for UA generation.
- OsFamily
- High-level OS family used for UA platform tokens.
- UaStrictness
- Controls how strictly the generated UA must match a detected browser installation.
Functions§
- build_
user_ agent - Build a
User-Agentstring using installed browser detection and the requested strictness. - choose_
best_ browser - Choose the “best” browser from a detected list, using OS-specific preference ordering.
- detect_
browsers - Detect installed browsers on the current OS.
- platform_
info - Collect platform information used for UA generation.