browser

package
v0.47.13 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2026 License: MIT Imports: 18 Imported by: 0 modules, 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

Overview

Package browser drives a Chrome the operator runs beside the server, over the DevTools protocol: a fresh, isolated context per run, a page in it, and the few things a model needs — navigate, read the page as a tree it can point into, click, type, scroll, wait, screenshot. Every navigation and every request the page makes go through the same address guard as fetching a page: nothing private, nothing link-local, unless the operator listed it. Downloads are refused.

Nothing here launches Chrome. It connects to an endpoint, and tests speak to an in-process fake.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Browser

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

Browser is a connection to a Chrome.

func Connect

func Connect(ctx context.Context, settings *Settings) (*Browser, error)

Connect reaches a browser at its endpoint.

func (*Browser) Close

func (self *Browser) Close() error

Close ends every context and the connection.

func (*Browser) NewContext

func (self *Browser) NewContext(ctx context.Context) (*Context, error)

NewContext opens a context and a blank page in it.

type Context

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

Context is a fresh, isolated browser context with one page in it: no cookies, no storage, no history from anyone else.

func (*Context) Back

func (self *Context) Back(ctx context.Context) (*Location, error)

Back goes to the previous page.

func (*Context) Click

func (self *Context) Click(ctx context.Context, where Target) (string, *Location, error)

Click clicks an element and reports what it was and where the page went.

func (*Context) Close

func (self *Context) Close() error

Close discards the context and everything in it.

func (*Context) Evaluate

func (self *Context) Evaluate(ctx context.Context, expression string, maximum int) (string, error)

Evaluate runs an expression and returns its JSON value, bounded.

func (*Context) Hover

func (self *Context) Hover(ctx context.Context, where Target) (string, error)

Hover moves the pointer over an element.

func (*Context) LastUsed

func (self *Context) LastUsed() time.Time

LastUsed is when the context last did anything, for the idle sweep.

func (*Context) Navigate

func (self *Context) Navigate(ctx context.Context, address string) (*Location, error)

Navigate opens an address, after the guard, and waits for the page to load.

func (*Context) Press

func (self *Context) Press(ctx context.Context, key string) error

Press presses a key: Enter, Tab, Escape, ArrowDown, or a character.

func (*Context) Screenshot

func (self *Context) Screenshot(ctx context.Context, fullPage bool) ([]byte, error)

Screenshot is the viewport, or the whole page, as PNG.

func (*Context) Scroll

func (self *Context) Scroll(ctx context.Context, direction string, amount int, where Target) error

Scroll scrolls the page, or an element, by a number of viewports.

func (*Context) Select

func (self *Context) Select(ctx context.Context, where Target, value string, index int) (string, error)

Select chooses an option of a select by value, text or index.

func (*Context) Snapshot

func (self *Context) Snapshot(ctx context.Context, mode string, maximum int) (*Snapshot, error)

Snapshot reads the page: interactive, with refs, or text.

func (*Context) Type

func (self *Context) Type(ctx context.Context, where Target, text string, clearFirst, submit bool) error

Type types into an element, whatever kind it is. It is the person's agent doing what they asked; what stands between it and a field is the card they answer, not a list of fields kept here.

func (*Context) Wait

func (self *Context) Wait(ctx context.Context, condition, selector string, timeout time.Duration) (string, error)

Wait waits for a load, a selector, or the network to go quiet, up to a timeout, and says what ended it.

type Location

type Location struct {
	URL    string `json:"url"`
	Title  string `json:"title"`
	Status int    `json:"status,omitempty"`
}

Location is where a navigation ended.

type Settings

type Settings struct {
	// Endpoint is http://host:9222 or a ws:// debugger address.
	Endpoint string

	// AllowPrivate lists hosts or CIDRs the operator lets the browser
	// reach although they are private.
	AllowPrivate []string

	// ProxyListen is where the guarded proxy binds. Empty means every
	// address on an unused port, and Chrome is told the address its own
	// connection to this server came from -- which is reachable from
	// wherever it is running.
	ProxyListen string
}

Settings are what a browser needs.

type Snapshot

type Snapshot struct {
	Title     string `json:"title"`
	URL       string `json:"url"`
	Text      string `json:"text"`
	Truncated bool   `json:"truncated"`
}

Snapshot is the page as the model reads it.

type Target

type Target struct {
	Ref      int    `json:"ref"`
	Selector string `json:"selector"`
}

Target describes how an action names its element: a ref from the last snapshot, or a selector.

Jump to

Keyboard shortcuts

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