v0.3.3

Option Fields

Last updated


Every field of browser.Option, the value used when it is left at its zero value, and how fields interact.

Fields


FieldTypeWhen unsetNotes
IdleWaittime.Duration2sCap for each settle, SettleJS and consent evaluation; the DOM stability window is min(400ms, IdleWait)
MaxLengthint1048576 (1 << 20)Markdown output is cut to this many bytes, which can split a multi-byte character; a negative value disables truncation; ignored by TypeHTML and TypeJSON
UserAgentstringDefaultUserAgentAlso part of the browser cache key
KeepLinksboolfalseKeep links, images and nav / header / footer / aside in converted output
StealthJSstringembedded stealth.jsInjected with EvalOnNewDocument; replaces the default, an empty string restores it, see Anti-Detection
SettleJSstringembedded listener.jsEvaluated once after the DOM settles; an empty string restores the default
Viewport*Viewport1280 × 960DeviceScaleFactor 0 is treated as 1
SameSessionboolfalseTemporary profile with local Chrome cookies, see Cookie Sessions
HeadlessboolfalseForces headless with no headed retry
VisibleboolfalseGoes headed directly with no retry when a GUI is available; without a GUI it falls back to headless first. Ignored when Headless is true, see Fetch Routing
Profilestring"Default"Chrome profile directory name, used only with SameSession
TypeintTypeMarkdownTypeMarkdown, TypeHTML or TypeJSON, see Output Formats
ScrollCountint3A negative value means no scrolling

Fetch copies the Option before filling defaults, so the value you pass is never modified and can be reused across calls.

Viewport


  1. type Viewport struct {
  2. Width int
  3. Height int
  4. DeviceScaleFactor float64
  5. }

Field interactions


CombinationEffect
Headless: true + session domainHeadless wins; the session domain list is ignored
Headless: true + Visible: trueHeadless wins; Visible is ignored
Visible: true without a GUISame as unset: headless first, headed retry not possible
Headless: true + SameSession: trueA headless browser on the temporary cookie profile
SameSession: false + ProfileProfile has no effect
ScrollCount: 0Treated as unset, so 3 passes; use -1 to disable
IdleWait below 400msThe DOM stability window shrinks to IdleWait

Example


  1. result, err := browser.Fetch(ctx, href, 45*time.Second, &browser.Option{
  2. Type: browser.TypeMarkdown,
  3. KeepLinks: true,
  4. ScrollCount: 5,
  5. IdleWait: 3 * time.Second,
  6. Viewport: &browser.Viewport{Width: 1440, Height: 2000},
  7. })
中文