chrome

package
v1.82.0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package chrome starts a headed Chrome and connects to it over the DevTools protocol, the way a page behind a bot check needs it driven.

The DevTools port is chosen here and given to Chrome by number: a Chrome told port 0, or driven over --remote-debugging-pipe, declares itself automated to every page (navigator.webdriver is true), and Cloudflare's Turnstile then never passes. Headless is refused outright, so Chrome needs a display, Xvfb in a container.

Index

Constants

This section is empty.

Variables

View Source
var DefaultFlags = []string{
	"--no-first-run",
	"--no-default-browser-check",
	"--no-sandbox",
	"--disable-dev-shm-usage",
	"--password-store=basic",
	"--window-size=1280,720",

	"--disable-background-networking",
}

DefaultFlags are what Chrome is started with besides the profile and the port. The sandbox needs namespaces a container does not give, and /dev/shm in a container is too small for Chrome's shared memory.

View Source
var ErrChromeExited = errors.New("chrome exited")

ErrChromeExited is Chrome gone before it listened.

Functions

func DevToolsEndpoint

func DevToolsEndpoint(ctx context.Context, port int, exited <-chan struct{}) (string, error)

DevToolsEndpoint waits for Chrome to listen on its port and returns the browser's own endpoint there, from the version it reports. With a fixed port Chrome writes no DevToolsActivePort file to read it from instead.

func FreePort

func FreePort(ctx context.Context) (int, error)

FreePort returns a loopback port nothing is listening on. Another process could take it before Chrome does; nothing is done about that race.

Types

type Browser

type Browser struct {
	Conn *cdp.Conn
	// contains filtered or unexported fields
}

Browser is a running Chrome and the connection to it.

func Launch

func Launch(ctx context.Context, chromePath string, profileDirectory string, flags ...string) (*Browser, error)

Launch starts Chrome on the profile directory with DefaultFlags and the flags given, and connects to it. Chrome is killed, with every process it started, when the context ends; Close ends it sooner, and more gently.

func (*Browser) Close

func (b *Browser) Close(ctx context.Context)

Close asks Chrome to close and kills it, group and all, when it does not in time. It runs to the end even when the context has ended -- a Chrome whose context ended has been killed already, and the asking then fails at once.

func (*Browser) NewPage

func (b *Browser) NewPage(ctx context.Context) (*Page, error)

NewPage opens a blank tab and attaches to it.

type Page

type Page struct {
	TargetId  string
	SessionId string
}

Page is a tab of the browser and the session it is addressed through.

func NewPage

func NewPage(ctx context.Context, caller cdp.Caller) (*Page, error)

NewPage opens a blank tab in the browser behind the caller and attaches to it, flattened, so that its session id addresses it on the same connection.

Jump to

Keyboard shortcuts

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