browser

package
v1.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 35 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseChromeWSHeaders added in v1.9.0

func ParseChromeWSHeaders(lines []string) (http.Header, error)

ParseChromeWSHeaders converts "Name: Value" lines (as given to -chrome-ws-header) into an http.Header. Empty lines are skipped.

func RedactHeaderLine added in v1.9.0

func RedactHeaderLine(line string) string

RedactHeaderLine hides the value of a "Name: Value" header so credentials do not end up in logs or error messages.

Types

type BrowserPage

type BrowserPage struct {
	*rod.Page

	Browser *rod.Browser
	// contains filtered or unexported fields
}

BrowserPage is a combination of a browser and a page

func (*BrowserPage) CloseBrowserPage

func (b *BrowserPage) CloseBrowserPage()

func (*BrowserPage) CurrentPage added in v1.9.0

func (b *BrowserPage) CurrentPage() *rod.Page

CurrentPage returns the page stored by the crawler.

func (*BrowserPage) FindNavigations

func (b *BrowserPage) FindNavigations() ([]*types.Action, error)

FindNavigation attempts to find more navigations on the page which could be done to find more links and pages.

This includes the following -

  1. Forms
  2. Buttons
  3. Links
  4. Elements with event listeners

The navigations found are unique across the page. The caller needs to ensure they are unique globally before doing further actions with details.

func (*BrowserPage) GetAllElements

func (b *BrowserPage) GetAllElements(selector string) ([]*types.HTMLElement, error)

func (*BrowserPage) GetAllForms

func (b *BrowserPage) GetAllForms() ([]*types.HTMLForm, error)

func (*BrowserPage) GetClickListenerElements added in v1.9.0

func (b *BrowserPage) GetClickListenerElements() ([]*types.HTMLElement, error)

func (*BrowserPage) GetElementFromXpath

func (b *BrowserPage) GetElementFromXpath(xpath string) (*types.HTMLElement, error)

func (*BrowserPage) GetEventListeners

func (b *BrowserPage) GetEventListeners() ([]*types.EventListener, error)

GetEventListeners returns all event listeners on the page

func (*BrowserPage) GetInteractiveElements added in v1.9.0

func (b *BrowserPage) GetInteractiveElements(selector, exclude string) ([]*types.HTMLElement, error)
func (b *BrowserPage) GetNavigatedLinks() ([]*NavigatedLink, error)

GetNavigatedLinks returns all navigated links on the page

func (*BrowserPage) RevealLazyContent added in v1.9.0

func (b *BrowserPage) RevealLazyContent(maxSteps int, settle time.Duration) (int, error)

RevealLazyContent performs a bounded number of viewport-sized scrolls before navigation discovery. This activates common infinite-scroll and lazy-render handlers while retaining a hard work limit for pages that never stop growing.

func (*BrowserPage) SetPage added in v1.9.0

func (b *BrowserPage) SetPage(p *rod.Page)

SetPage stores the page the crawler is using. The dialog goroutine reads it through CurrentPage, so the swap with page.Context is not a data race and the callbacks still observe the crawl context.

func (*BrowserPage) WaitNewStable

func (p *BrowserPage) WaitNewStable(d time.Duration) error

WaitStable waits until the page is stable for d duration.

func (*BrowserPage) WaitPageLoadHeurisitics

func (b *BrowserPage) WaitPageLoadHeurisitics() error

WaitPageLoadHeurisitics waits for the page to load using multiple heuristics. Strategy order:

  1. Wait for initial load event (covers classic navigation & first paint).
  2. Poll for a URL change – the strongest signal on SPAs with client-side routing.
  3. If URL changes, wait a short grace period + network-idle window.
  4. If URL doesn't change, fall back to network-idle + DOM-stable windows.

This keeps fast pages fast while still succeeding on noisy, long-running SPAs.

func (*BrowserPage) WaitPageLoadHeuristicsFallback

func (b *BrowserPage) WaitPageLoadHeuristicsFallback() error

WaitPageLoadHeuristicsFallback provides the enhanced timeouts for complex navigation

type Launcher

type Launcher struct {
	// contains filtered or unexported fields
}

Launcher is a high level controller to launch browsers and do the execution on them.

func NewLauncher

func NewLauncher(opts LauncherOptions) (*Launcher, error)

NewLauncher returns a new launcher instance

func (*Launcher) AdoptPopup added in v1.9.0

func (l *Launcher) AdoptPopup(page *rod.Page, browser *rod.Browser) (*BrowserPage, error)

AdoptPopup prepares a browser-created tab for the same response capture and interactive helpers used by a pooled page. Call it as soon as the target is discovered (even while still about:blank) so Fetch interception is enabled before the popup's first navigation races ahead. The caller owns and closes it.

func (*Launcher) Close

func (l *Launcher) Close()

Close closes the launcher

func (*Launcher) GetPageFromPool

func (l *Launcher) GetPageFromPool() (*BrowserPage, error)

GetPageFromPool returns a page from the pool

func (*Launcher) PutBrowserToPool

func (l *Launcher) PutBrowserToPool(browser *BrowserPage)

func (*Launcher) ScopeValidator

func (l *Launcher) ScopeValidator() ScopeValidator

type LauncherOptions

type LauncherOptions struct {
	UseInstalledChrome  bool
	ChromiumPath        string
	MaxBrowsers         int
	PageMaxTimeout      time.Duration
	ShowBrowser         bool
	NoSandbox           bool
	NoIncognito         bool
	Proxy               string
	SlowMotion          bool
	Trace               bool
	CookieConsentBypass bool
	PageLoadStrategy    string
	ChromeWSUrl         string            // WebSocket URL to connect to existing Chrome
	ChromeWSHeaders     http.Header       // headers sent when connecting to ChromeWSUrl (e.g. Authorization)
	DOMWaitTime         int               // Time in seconds to wait for DOM (used with domcontentloaded strategy)
	UserDataDir         string            // User-provided chrome data directory to preserve sessions
	ChromeUser          *user.User        // optional chrome user to use
	UserArguments       map[string]string // user-supplied Chrome flags via -headless-options
	CustomHeaders       map[string]string
	CookieURL           string

	ScopeValidator  ScopeValidator
	RequestCallback func(*output.Result)
	Interactive     bool
	// TrafficCallback, when set, receives every intercepted exchange,
	// including redirects and failures, before any crawl filtering.
	TrafficCallback func(*output.Result)
}

LauncherOptions contains options for the launcher

type NavigatedLink struct {
	URL    string `json:"url"`
	Source string `json:"source"`
}

NavigatedLink is a link navigated collected from one of the navigation hooks.

type ScopeValidator

type ScopeValidator func(string) bool

type WaitOptions

type WaitOptions struct {
	URLPollInterval time.Duration // interval between successive URL polls
	URLPollTimeout  time.Duration // how long to keep polling before giving up on URL change
	PostChangeWait  time.Duration // small grace period after URL change for late requests
	IdleWait        time.Duration // network-idle window when no URL change happened
	DOMStableWait   time.Duration // DOM-stable window (used after idle)
	MaxTimeout      time.Duration // absolute upper bound for all waiting
}

WaitOptions controls how WaitPageLoadHeurisitics determines navigation completion. All durations are conservative defaults and can be tuned later via package-level variables or future setter methods (kept simple here to avoid breaking public API).

Directories

Path Synopsis
Package cookie implements cookie consent handling for the crawler.
Package cookie implements cookie consent handling for the crawler.
from stealth go-rod
from stealth go-rod

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL