Documentation
¶
Overview ¶
Package browserheaders generates a coherent set of browser-typical HTTP request headers for outbound calls that need to evade trivial bot detection.
The fleet's canonical "I'm a bot, please rate-limit me" User-Agent (`ua.Build`) is appropriate for inbound APIs that want to be identified — but lethal for outbound calls to anti-bot endpoints like DuckDuckGo, Cloudflare-protected sites, etc.
Why "coherent set" ¶
Modern bot detectors (DDG, Cloudflare, Akamai, PerimeterX, DataDome) check that headers are internally consistent. Examples:
- Chrome's User-Agent → must come with Sec-Ch-Ua "Google Chrome"
- Firefox's User-Agent → must NOT send Sec-Ch-Ua
- Safari's User-Agent → must NOT send Sec-Ch-Ua
- Accept-Encoding should always include "br" on modern browsers
- Sending Referer together with Sec-Fetch-Site: none is contradictory; use ApplyNavigation to keep Sec-Fetch-Site aligned with Referer.
Mixing Chrome's UA with Firefox's Sec-Ch-Ua absence is a tell. So we rotate full personas (browser+OS+version), not individual fields.
Usage ¶
persona := browserheaders.Random() persona.Apply(req.Header) // or with navigation Referer + consistent Sec-Fetch-Site: persona.ApplyNavigation(req.Header, req.URL.String(), "https://duckduckgo.com/")
Index ¶
Constants ¶
const ( FamilyChrome = "chrome" FamilyFirefox = "firefox" FamilySafari = "safari" )
Browser family constants so TLS-impersonating callers can match the TLS ClientHello (e.g. Chrome/Firefox/Safari) to the chosen HTTP persona.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Persona ¶
type Persona struct {
Family string // FamilyChrome, FamilyFirefox, or FamilySafari
UserAgent string
Accept string
AcceptLanguage string
AcceptEncoding string
SecChUa string // empty if not a Chromium-family browser
SecChUaMobile string // ?0 (desktop) or ?1 (mobile)
SecChUaPlatform string // "macOS" / "Windows" / "Linux" / etc.
// Set Upgrade-Insecure-Requests: 1
UpgradeInsecure bool
// Set DNT: 1
DoNotTrack bool
}
Persona is one self-consistent browser identity.
func Personas ¶
func Personas() []Persona
Personas returns a copy of the internal persona list. Useful for tests and for callers that want to filter (e.g. desktop-only).
func Random ¶
func Random() Persona
Random returns a random Persona from the pool. Safe for concurrent use; uses the default math/rand source.
func (Persona) Apply ¶
Apply writes the persona's headers into h, replacing any existing values for these keys. Assumes a direct navigation (Sec-Fetch-Site: none).
func (Persona) ApplyNavigation ¶ added in v0.140.0
ApplyNavigation writes the persona's headers into h and sets Referer and Sec-Fetch-Site consistently with targetURL and referer:
- empty referer -> Sec-Fetch-Site: none (no Referer header)
- same scheme+host -> Sec-Fetch-Site: same-origin
- same registrable parent domain (e.g. duckduckgo.com -> html.duckduckgo.com) -> Sec-Fetch-Site: same-site
- different domain -> Sec-Fetch-Site: cross-site