browser

package
v0.99.17 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package browser provides a CDP-backed browser session for agent tools.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertNavigateURL

func AssertNavigateURL(raw string, allowPrivate bool, allowHosts []string) error

AssertNavigateURL validates a navigation target against SSRF policy. allow_hosts is an explicit exception list. When allowPrivate is true, RFC1918 private addresses are permitted, but loopback, link-local, and cloud-metadata hosts remain blocked unless listed in allow_hosts.

func WithSession

func WithSession(ctx context.Context, s *Session) context.Context

WithSession attaches a Session to ctx for browser tools.

Types

type Config

type Config struct {
	Driver       Driver
	Endpoint     string
	AllowPrivate bool
	AllowHosts   []string
	Timeout      time.Duration
}

Config configures a browser session.

func (Config) Normalize

func (c Config) Normalize() (Config, error)

Normalize fills defaults and validates driver/endpoint.

func (Config) Quirks

func (c Config) Quirks() Quirks

Quirks returns driver-specific behavior flags.

type Driver

type Driver string

Driver selects CDP backend quirks.

const (
	// DriverLightpanda is the Lightpanda headless browser CDP server.
	DriverLightpanda Driver = "lightpanda"
	// DriverPlaywright is Chromium exposed via remote-debugging CDP
	// (compose profile playwright-cdp), not the Playwright Test runner.
	DriverPlaywright Driver = "playwright"

	// MaxScreenshotBytes caps PNG bytes returned by Screenshot.
	MaxScreenshotBytes = 2 << 20
)

type Quirks

type Quirks struct {
	PreferNetworkIdle bool
}

Quirks holds per-driver capability differences.

type Session

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

Session is a per-run isolated browser context with serialized operations.

func FromContext

func FromContext(ctx context.Context) (*Session, bool)

FromContext returns the Session attached to ctx, if any.

func NewSession

func NewSession(cfg Config) (*Session, error)

NewSession creates a lazy session. CDP connects on first operation.

func (*Session) Click

func (s *Session) Click(ctx context.Context, ref string) error

Click activates the element identified by ref from the last Snapshot.

func (*Session) Close

func (s *Session) Close() error

Close tears down the CDP browser context.

func (*Session) Config

func (s *Session) Config() Config

Config returns the session configuration.

func (*Session) Navigate

func (s *Session) Navigate(ctx context.Context, rawURL string) (string, error)

Navigate loads url after URL-gate checks and clears refs.

func (*Session) Screenshot

func (s *Session) Screenshot(ctx context.Context) ([]byte, error)

Screenshot captures a PNG of the current page.

func (*Session) Scroll

func (s *Session) Scroll(ctx context.Context, dx, dy int) error

Scroll scrolls the page by dx, dy pixels.

func (*Session) Snapshot

func (s *Session) Snapshot(ctx context.Context) (string, error)

Snapshot returns a compact interactive tree with opaque refs.

func (*Session) Type

func (s *Session) Type(ctx context.Context, ref, text string) error

Type focuses ref and types text.

func (*Session) Wait

func (s *Session) Wait(ctx context.Context, ms int) error

Wait pauses or waits for network idle depending on driver quirks.

Jump to

Keyboard shortcuts

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