livebrowser

package
v0.16.521 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: AGPL-3.0 Imports: 27 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 livebrowser is the machine's real browser for the pane: a headless Chrome the runtime starts when a browser tab of the pane opens an outside site, driven over the DevTools protocol (CDP). The page's picture goes to the pane as a screencast, the person's mouse, keys, wheel and paste go back as input events, and the agent's tools act on the page through the same protocol. The proxy (internal/preview) keeps the machine's own servers and stands, where the page is rewritten, inspected and edited; this browser takes the sites the proxy cannot carry.

The browser is driven over a pipe (--remote-debugging-pipe), not a DevTools port: no process or page on the machine can reach the protocol, and so the profile's cookies, except the runtime through the pipe it holds.

Index

Constants

This section is empty.

Variables

View Source
var ErrClosed = errors.New("the browser's connection is closed")

ErrClosed: the browser's connection is gone.

Functions

func EnvArgs

func EnvArgs(value string) []string

EnvArgs reads a flag list from the environment: words split on spaces.

Types

type Act

type Act struct {
	ID     string `json:"id"`
	Op     string `json:"op"`
	Ref    string `json:"ref"`
	Text   string `json:"text"`
	Key    string `json:"key"`
	Value  string `json:"value"`
	DY     int    `json:"dy"`
	MS     int    `json:"ms"`
	Submit bool   `json:"submit"`
	// Event is what a wait is for on a video or audio: ended, playing or paused.
	Event string `json:"event"`
	Tool  string `json:"tool"`
	Input string `json:"input"`
	// Host is the site the person let the agent act on: a page that moved to another site since is not acted on.
	Host string `json:"host"`
	// contains filtered or unexported fields
}

Act is one action: op is snapshot, locate, click, type, press, hover, select, scroll, wait, tools or call; navigate and back are the tab's (the pane does them through the socket's nav and back).

type Acted

type Acted struct {
	ID   string `json:"id"`
	OK   bool   `json:"ok"`
	Text string `json:"text"`
	Rect *Rect  `json:"rect"`
}

Acted is what an action came to; Rect is its element's box, for the agent's cursor in the pane.

type Config

type Config struct {
	// DataDir is the runtime's data directory: the browser's profile (cookies, sign-ins) lives in its live-browser/.
	// One runtime is one person on one machine, so the profile is theirs alone.
	DataDir string
	// Binary is the browser to run; empty looks for google-chrome, chromium and their variants on PATH.
	Binary string
	// ExtraArgs are added to the browser's command line (RUNTIME_LIVE_BROWSER_ARGS).
	ExtraArgs []string
	// MaxTabs bounds the pages open at once; a tab past it is refused.
	MaxTabs int
	// IdleAfter closes the browser once no tab has been open for this long.
	IdleAfter time.Duration
	// Nice lowers the browser's priority (0 keeps it).
	Nice int
	// Local are the machine's own addresses (preview.SelfAddresses); Lookup resolves names (nil for the system's).
	// Together they decide what the browser may load: see Refusal.
	Local  map[string]bool
	Lookup preview.Lookup
	// Log takes the service's notes.
	Log func(level, msg string, kv ...any)
}

Config is how the service runs the browser.

type Event

type Event struct {
	SessionID string
	Method    string
	Params    json.RawMessage
}

Event is what Chrome tells of its own: a method with parameters, for the session it belongs to ("" for the browser).

type Frame

type Frame struct {
	Data   []byte
	Width  int
	Height int
}

Frame is one picture of the page: JPEG bytes and the page's CSS size they show.

type Info

type Info struct {
	URL        string `json:"url"`
	Title      string `json:"title"`
	CanBack    bool   `json:"canBack"`
	CanForward bool   `json:"canForward"`
	Loading    bool   `json:"loading"`
}

Info is what the pane shows of the page besides its picture.

type Rect

type Rect struct {
	X      float64 `json:"x"`
	Y      float64 `json:"y"`
	Width  float64 `json:"width"`
	Height float64 `json:"height"`
}

Rect is an element's box in the page's viewport, CSS pixels.

type Service

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

Service owns the one browser of the runtime: started on the first tab, closed when idle or when it dies.

func New

func New(cfg Config) *Service

New is a service with the defaults filled in.

func (*Service) Available

func (s *Service) Available() bool

Available says whether a browser binary is on this machine.

func (*Service) Close

func (s *Service) Close()

Close stops the browser.

func (*Service) Open

func (s *Service) Open(ctx context.Context, id string, width, height int, scale float64) (*Tab, error)

Open gives a tab for the id (the pane's tab), starting the browser when it is not running. A tab that already exists is returned as it is: a page survives a reload of the pane. Past MaxTabs, the request is refused.

func (*Service) ProfileDir

func (s *Service) ProfileDir() string

ProfileDir is where the browser keeps the person's cookies and sign-ins.

func (*Service) Refusal

func (s *Service) Refusal(raw string) string

Refusal says why an address may not open in the live browser: "" when it may. The browser runs on the machine, so its servers and the private networks behind it stay with the proxy, which knows what is allowed there. The rule holds for every connection the browser makes, not only the address typed: see egress.

func (*Service) Running

func (s *Service) Running() bool

Running says whether the browser is up.

func (*Service) Tabs

func (s *Service) Tabs() int

Tabs is how many pages are open.

type Socket

type Socket struct {
	S   *Service
	Log func(level, msg string, kv ...any)
}

Socket serves the pane's connection to a tab.

func (*Socket) ServeHTTP

func (sk *Socket) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP upgrades an authenticated request and drives the tab until either side closes.

type Tab

type Tab struct {
	ID string
	// contains filtered or unexported fields
}

Tab is one page of the browser, shown in one browser tab of the pane.

func (*Tab) Acked

func (t *Tab) Acked()

Acked: the pane drew (or dropped) a picture; the pump may send the next, and the browser hears of one more taken.

func (*Tab) Act

func (t *Tab) Act(ctx context.Context, a Act) Acted

Act runs one action on the page and never fails loudly: a page that breaks it answers with words.

func (*Tab) Back

func (t *Tab) Back() error

Back and Forward step through the page's history; Reload loads it again.

func (*Tab) Close

func (t *Tab) Close()

Close ends the page.

func (*Tab) Ended

func (t *Tab) Ended() <-chan struct{}

Ended is closed when the tab is gone; Why says why.

func (*Tab) Evaluate

func (t *Tab) Evaluate(expression string, result any) error

Evaluate runs an expression in the page and returns its value as JSON.

func (*Tab) Forward

func (t *Tab) Forward() error

func (*Tab) Frames

func (t *Tab) Frames() <-chan Frame

Frames is the page's pictures, the newest only.

func (*Tab) Info

func (t *Tab) Info() (Info, error)

Info reads the page's address, title and history from the browser.

func (*Tab) InsertText

func (t *Tab) InsertText(text string) error

InsertText types text as one piece (a paste, an IME's composition).

func (*Tab) Key

func (t *Tab) Key(kind, key, code, text string, vk, modifiers int) error

Key sends a key: kind is keyDown or keyUp; text is what a printable key types.

func (*Tab) Mouse

func (t *Tab) Mouse(kind string, x, y float64, button string, buttons, modifiers, clicks int) error

Mouse sends a pointer event: kind is mousePressed, mouseReleased or mouseMoved; x and y are CSS pixels.

func (*Tab) Navigate

func (t *Tab) Navigate(url string) error

Navigate opens an address.

func (*Tab) Paced

func (t *Tab) Paced(on bool)

Paced: whether the pane acks the pictures it draws.

func (*Tab) Reload

func (t *Tab) Reload() error

func (*Tab) Resize

func (t *Tab) Resize(width, height int, scale float64) error

Resize gives the page a new CSS size and pixel scale; the screencast follows.

func (*Tab) Selection

func (t *Tab) Selection() (string, error)

Selection is the text the page has selected, for the person's clipboard.

func (*Tab) Sent

func (t *Tab) Sent()

Sent: a picture went out to the pane.

func (*Tab) StartScreencast

func (t *Tab) StartScreencast() error

StartScreencast asks for the page's pictures as they change; one that runs is started over (a new size).

func (*Tab) StopScreencast

func (t *Tab) StopScreencast() error

StopScreencast ends the pictures while nobody looks.

func (*Tab) Touched

func (t *Tab) Touched()

Touched: the person or the agent did something, or the page moved: the page is in motion, its pictures go on.

func (*Tab) Updates

func (t *Tab) Updates() <-chan Info

Updates is what changed about the page, the newest only.

func (*Tab) WaitSlot

func (t *Tab) WaitSlot(ctx context.Context) bool

WaitSlot waits until the pane has room for one more picture: at once for a pane that does not ack; a pane silent for holdMax is not waited for any longer. False when the context ended.

func (*Tab) Wheel

func (t *Tab) Wheel(x, y, dx, dy float64, modifiers int) error

Wheel scrolls at a point.

func (*Tab) Why

func (t *Tab) Why() string

Jump to

Keyboard shortcuts

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