uagent 0.1.0

Browser user agents with matching navigation headers and deterministic profile selection.
Documentation
  • Coverage
  • 100%
    24 out of 24 items documented3 out of 3 items with examples
  • Size
  • Source code size: 86.5 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 578.6 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 1s Average build duration of successful builds.
  • all releases: 1s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • spire-rs/uagent
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • martsokha

uagent

Build Status Crate Docs Crate Version

Check out other spire projects here.

Browser profiles for Chrome, Edge, Firefox and Safari in the Rust programming language, with user agents, matching navigation headers and deterministic selection by relative browser and platform weights. Browser captures ship with the crate and require no data fetch during builds or at runtime.

Examples

  • create a browser profile and read its navigation headers:
use uagent::{Browser, Platform, Profile};

let profile = Profile::new(Browser::Chrome, Platform::Windows)?;
assert_eq!(profile.version(), Browser::Chrome.latest());

// Header structs are returned in capture order.
for header in profile.headers() {
    println!("{}: {}", header.name, header.value);
}
# Ok::<(), uagent::Error>(())
  • override the language preferences, validating BCP 47 tags and quality values:
use uagent::{Browser, Platform, Profile};

let profile = Profile::new(Browser::Firefox, Platform::MacOs)?
    .with_language("de-DE,de;q=0.9")?;
assert!(profile.headers().iter().any(|header| {
    header.name == "accept-language" && header.value == "de-DE,de;q=0.9"
}));
# Ok::<(), uagent::Error>(())
  • pick a profile for each crawler identity, deterministically by its number:
use uagent::{Browser, Platform, UserAgents};

let agents = UserAgents::new()
    .browsers([Browser::Chrome, Browser::Firefox])
    .share(Browser::Firefox, 20)
    .platforms([Platform::Windows, Platform::MacOs])
    .versions(Browser::Chrome, 155..=156)
    .language("en-US,en;q=0.9")?;

assert_eq!(agents.pick(42), agents.pick(42));
# Ok::<(), uagent::Error>(())

Links

Notes

  • Headers describe a page opened directly. Host, cookies, connection management and Accept-Encoding are left to the HTTP client. TLS and HTTP/2 emulation are outside this crate's scope.
  • Default browser weights are Chrome 65, Safari 18, Edge 10 and Firefox 7, with desktop platforms and the latest two major versions, or one for Safari. These weights are configurable approximations. Empty selections and invalid version ranges panic during configuration.
  • Selection is stable for the same configuration and crate version. Patch releases refresh captures; pin the crate version to retain exact profiles.
  • Initial captures cover macOS. Other platform variants originate from the Spire draft and have not been verified against captures. iOS browsers other than Safari, and Android Edge, are not modeled.
  • Other major versions reuse the latest captured navigation headers. Historical header changes are not modeled; Safari retains its captured minor/patch suffix.