browser

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package browser provides a small wrapper around a shared, reusable headless Chromium instance (via go-rod). Loading pages through a real browser lets the media extractors bypass anti-bot challenges that block plain HTTP clients.

Index

Constants

View Source
const UserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"

UserAgent is the desktop Chrome UA used for both navigation and any follow-up download requests that must look like they came from the same browser.

Variables

View Source
var ErrClosed = errors.New("browser manager is closed")

ErrClosed is returned by Load/Warmup after the Manager has been closed.

Functions

This section is empty.

Types

type Manager

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

Manager owns a lazily-launched, reused browser instance.

func Default

func Default() *Manager

Default returns the process-wide shared Manager.

func NewManager

func NewManager() *Manager

NewManager creates a browser manager. The Chromium binary path can be set via BROWSER_BIN (recommended in containers); otherwise go-rod locates or downloads a browser.

func (*Manager) Close

func (m *Manager) Close() error

Close marks the Manager closed, waits for in-flight Load calls to finish, then shuts the shared browser down. Safe to call multiple times. After Close, Load and Warmup return ErrClosed instead of relaunching a new browser.

func (*Manager) Load

func (m *Manager) Load(ctx context.Context, url string) (*Result, error)

Load opens url in the shared browser, waits for it to load, and returns the rendered HTML, the final URL (after redirects) and the visit cookies.

func (*Manager) Warmup

func (m *Manager) Warmup() error

Warmup launches the browser ahead of time so the first real request does not pay the cold-start cost (important for the time-boxed inline-query path).

type Result

type Result struct {
	FinalURL string                 // URL after redirects
	HTML     string                 // full rendered HTML
	Cookies  []*proto.NetworkCookie // cookies set during the visit
}

Result is the outcome of loading a page.

func (*Result) CookieHeader

func (r *Result) CookieHeader() string

CookieHeader renders the visit cookies into a Cookie request header value.

Jump to

Keyboard shortcuts

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