Skip to main content

Crate ua

Crate ua 

Source
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:

If you want more control, you can use:

§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 .exe file version metadata.
    • macOS: checks /Applications/*.app and reads Info.plist version metadata.
    • Linux: checks PATH binaries and optionally inspects Flatpak/Snap installs.
  • 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 Real mode 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§

BrowserInfo
Information about a detected browser installation.
PlatformInfo
Platform information used to build the UA platform token.
SemVerish
Parsed “version-like” representation extracted from browser version strings.

Enums§

AgentError
Errors returned by platform/browser detection and UA generation.
Arch
CPU architecture classification for UA platform tokens.
BrowserKind
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-Agent string 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.