#user-agent #fingerprinting #http #browser

ua

Cross-platform User-Agent generator with best-effort installed browser detection (Chrome/Edge/Firefox/Brave/Opera/Chromium; Safari best-effort)

3 releases

Uses new Rust 2024

0.1.2 Jan 26, 2026
0.1.1 Jan 26, 2026
0.1.0 Jan 26, 2026

#427 in HTTP client

MIT/Apache

45KB
983 lines

ua

Cross-platform User-Agent generator with best-effort installed browser detection.

This crate detects installed browsers and (when possible) uses their versions to generate realistic User-Agent strings. It supports Windows, macOS, and Linux.

Features

  • Platform detection (OS + CPU arch)
  • Installed browser detection (best-effort)
  • User-Agent generation:
    • Chromium family: Chrome / Edge / Chromium / Brave / Opera
    • Firefox
    • Safari (best-effort only)
  • Strictness modes:
    • Real: requires a detected browser version (Safari not supported)
    • BestEffort: falls back to safe defaults

Usage

use ua::{build_user_agent, UaStrictness};

let ua = build_user_agent(UaStrictness::BestEffort)?;
println!("{ua}");
# Ok::<(), ua::AgentError>(())

lib.rs:

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.

Dependencies

~0.1–3MB
~59K SLoC