Expand description
§uagent
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);
}- 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"
}));- 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));§Links
- User-Agent and Accept-Language in RFC 9110 on RFC-Editor.org
- Language Tags in RFC 5646 on RFC-Editor.org
- User-Agent Client Hints on Chrome for Developers
- Browser capture guide in this repository
§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.
Structs§
- Header
- A named header field in a browser profile.
- Profile
- A browser version and platform with navigation headers for a page opened directly.
- User
Agents - Selects browser profiles by relative browser and platform weights.
Enums§
- Browser
- A browser a
Profilepresents as. - Error
- An invalid browser profile configuration.
- Platform
- The platform a
Profileruns on.
Type Aliases§
- Result
- A result returned by browser profile configuration.