browser

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2026 License: Apache-2.0 Imports: 15 Imported by: 1 module, 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 performs computer-use actions in a browser context.

It speaks the Chrome DevTools Protocol over a WebSocket, which needs no driver binary, no cgo, and nothing on the machine except a Chromium that is already listening. A browser context is also the right default target: blast radius is bounded by what the browser can reach, and nothing here can touch an ambient desktop.

The surface it implements is nine methods wide and knows nothing about authority, confirmation, or auditing. Those live above it, which is what lets this file be only about making the browser do things.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// DevToolsURL is the browser's debugging endpoint, such as
	// http://127.0.0.1:9222. A page target is discovered through it.
	DevToolsURL string
	// TargetURL connects directly to a known page WebSocket instead, which is
	// what a deployment that manages its own tabs will have.
	TargetURL string
	// Timeout bounds one command.
	Timeout time.Duration
	// TypingDelay paces synthetic keystrokes. Zero types instantly, which is
	// correct for a form and wrong for a page that debounces input.
	TypingDelay time.Duration
}

Config configures the connection.

type MarkedElement

type MarkedElement struct {
	ID     string `json:"id"`
	Role   string `json:"role,omitempty"`
	Name   string `json:"name,omitempty"`
	X      int    `json:"x"`
	Y      int    `json:"y"`
	Width  int    `json:"width"`
	Height int    `json:"height"`
}

MarkedElement describes one interactive element in a set-of-mark frame. Bounds use the same CSS-pixel coordinate space as the video source.

type Surface

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

Surface drives one browser page.

func Connect

func Connect(ctx context.Context, config Config) (*Surface, error)

Connect opens a page and returns a surface over it.

func (*Surface) Capture

func (surface *Surface) Capture(ctx context.Context) ([]byte, error)

Capture returns a screenshot, for a caller that is feeding the video stream rather than acting.

func (*Surface) CaptureMarked

func (surface *Surface) CaptureMarked(ctx context.Context) ([]byte, []MarkedElement, error)

CaptureMarked labels visible interactive DOM elements and captures the resulting page. The labels are part of the pixels the model sees; the returned metadata exists for audit and scoring, never as a model shortcut.

Labels persist on their target elements across captures while the red marker bubbles themselves are removed immediately after the screenshot. That makes computer.click_element stable without changing the page a person would use.

func (*Surface) Click

func (surface *Surface) Click(ctx context.Context, x, y int, button string) error

Click presses and releases a mouse button at a point.

func (*Surface) ClickElement

func (surface *Surface) ClickElement(ctx context.Context, elementID string) error

ClickElement clicks the centre of an element carrying the mark shown in the most recent marked frame. It still dispatches ordinary pointer events: the DOM is used only to resolve the label into the pixel space the model saw.

func (*Surface) Close

func (surface *Surface) Close() error

Close ends the connection.

func (*Surface) DoubleClick

func (surface *Surface) DoubleClick(ctx context.Context, x, y int) error

DoubleClick sends a two-click sequence.

func (*Surface) Drag

func (surface *Surface) Drag(ctx context.Context, fromX, fromY, toX, toY int) error

Drag presses at one point, moves, and releases at another.

func (*Surface) Evaluate

func (surface *Surface) Evaluate(ctx context.Context, expression string, destination any) error

Evaluate runs an operator expression and decodes its value.

Like Navigate, this is not a computer-use action. It exists for an environment owner to reset and score a task through a deliberately separate control plane. The model never receives this method or its result.

func (*Surface) Key

func (surface *Surface) Key(ctx context.Context, keys []string) error

Key presses a combination of keys together.

func (*Surface) Location

func (surface *Surface) Location(ctx context.Context) (string, error)

Location reports where the page currently is.

func (*Surface) Move

func (surface *Surface) Move(ctx context.Context, x, y int) error

Move moves the pointer without pressing anything.

func (*Surface) Name

func (surface *Surface) Name() string

Name identifies the surface in audit records.

func (*Surface) Navigate

func (surface *Surface) Navigate(ctx context.Context, url string) error

Navigate points the page at a URL and waits for the load to finish.

It is not an action in the computer-use namespace and is deliberately not one. A model that could navigate by naming a URL would be reaching past the page it was shown - the whole grounding argument for this vocabulary is that an action lands somewhere the model actually looked at. So this is here for the operator setting up a run, and it is not offered to a session.

func (*Surface) Screenshot

func (surface *Surface) Screenshot(ctx context.Context) error

Screenshot captures the page.

The bytes are discarded here rather than returned, and deliberately: the result of an action is the next screen, and the screen arrives through the video stream. Carrying an image back through a function result would put the same picture on two paths.

func (*Surface) Scroll

func (surface *Surface) Scroll(ctx context.Context, x, y, deltaX, deltaY int) error

Scroll scrolls at a point.

func (*Surface) Type

func (surface *Surface) Type(ctx context.Context, text string) error

Type inserts literal text.

func (*Surface) Viewport

func (surface *Surface) Viewport(ctx context.Context) (width, height int, err error)

Viewport reports the page's coordinate space, which is what a computer-use target must declare.

Jump to

Keyboard shortcuts

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