Documentation

Configuration

Configuration options for go-browser — Option fields, environment variables, Chrome profile paths, and output format types.

Option Fields

The Option struct controls all aspects of fetch and tab behavior. Passed to Fetch, CreateTab, and related functions.

Field Type Default Description
IdleWait time.Duration 2s Time to wait for DOM stability after page load or scroll
MaxLength int 1 << 20 (1MB) Maximum content length in bytes; truncates if exceeded
UserAgent string DefaultUserAgent Custom User-Agent string for the browser
KeepLinks bool false Preserve links and images in Markdown/JSON output
StealthJS string embedded stealth.js Custom stealth JavaScript injected via EvalOnNewDocument
SettleJS string embedded listener.js Custom settle JavaScript for lazy-load detection
Viewport *Viewport {1280, 960, 1} Browser viewport dimensions and scale factor
SameSession bool false Use Chrome cookie session injection for login-required pages
Headless bool false Force headless mode; auto-selected when no display is available
Profile string "Default" Chrome profile name for cookie extraction
Type int TypeMarkdown (0) Output format: TypeMarkdown, TypeHTML, or TypeJSON
ScrollCount int 3 Number of scroll iterations for dynamic content capture

Default Option

When nil is passed to Fetch or CreateTab, the following defaults apply:

&Option{
    IdleWait:    2 * time.Second,
    MaxLength:   1 << 20,
    UserAgent:   DefaultUserAgent,
    StealthJS:   defaultStealthJS,
    SettleJS:    defaultListenerJS,
    Viewport:    &Viewport{Width: 1280, Height: 960, DeviceScaleFactor: 1},
    Profile:     "Default",
    ScrollCount: 3,
    Type:        TypeMarkdown,
}

Output Format Constants

const (
    TypeMarkdown = iota // 0 — Markdown (default)
    TypeHTML            // 1 — Raw HTML
    TypeJSON            // 2 — Structured JSON tree
)

Chrome Profile Paths

go-browser locates Chrome profiles at platform-specific paths for cookie extraction:

OS Profile Root
macOS ~/Library/Application Support/Google/Chrome/<Profile>
Linux ~/.config/google-chrome/<Profile>

The default profile name is "Default". Override via Option.Profile.

Chrome Binary Paths

go-browser searches for Chrome in the following locations:

OS Search Paths
macOS /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
macOS /Applications/Chromium.app/Contents/MacOS/Chromium
Linux google-chrome, google-chrome-stable, chromium, chromium-browser (via PATH)

Concurrency

The default concurrency limit is 8 simultaneous page loads. Override with SetMaxConcurrency:

goBrowser.SetMaxConcurrency(16)

Browser Idle Eviction

The singleton headless browser is automatically closed after 5 minutes of inactivity. The eviction check runs every 1 minute.

Platform Support

Feature macOS Linux Windows
Headless fetch
Headed fetch ✅ (requires DISPLAY)
Cookie session
Interactive tabs
中文