browser

package
v0.6.76 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: AGPL-3.0, Apache-2.0, MIT Imports: 23 Imported by: 0

Documentation

Overview

Package browser runs the sandbox's visible Chromium (DBX-45): Xvfb, Chromium with a CDP port the agent's Playwright MCP drives, x11vnc on localhost bridged to the /browser/vnc WebSocket, and the /preview/:port/* reverse proxy. The browser starts on demand (StartBrowser, a VNC viewer, or the first CDP connection) and stops when idle.

Index

Constants

View Source
const (
	DefaultDisplay     = ":99"
	DefaultCDPPort     = 9222
	DefaultVNCPort     = 5900
	DefaultIdleTimeout = 15 * time.Minute
	VNCPath            = "/browser/vnc"
)

Defaults.

Variables

This section is empty.

Functions

This section is empty.

Types

type Browser

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

Browser manages the browser stack.

func New

func New(opts Options) *Browser

New returns a Browser.

func (*Browser) Available

func (b *Browser) Available() bool

Available reports whether Chromium, Xvfb and x11vnc are installed.

func (*Browser) IdleLoop

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

IdleLoop stops the browser after IdleTimeout without streams or stream bytes.

func (*Browser) Info

func (b *Browser) Info() *devboxv1.BrowserInfo

Info returns the browser state.

func (*Browser) LastActivity

func (b *Browser) LastActivity() time.Time

LastActivity is the last time a stream carried bytes or the browser was started.

func (*Browser) Pipe

func (b *Browser) Pipe(a, c io.ReadWriteCloser)

Pipe copies bytes both ways, counting the stream and its activity.

func (*Browser) PlaywrightMCP

func (b *Browser) PlaywrightMCP(command string) map[string]any

PlaywrightMCP is the stdio MCP server entry that drives this browser, added to every session when the image ships playwright-mcp.

func (*Browser) ServeCDP

func (b *Browser) ServeCDP(ctx context.Context) error

ServeCDP accepts agent CDP connections on 127.0.0.1:CDPPort, starting the browser on first use.

func (*Browser) ServeVNC

func (b *Browser) ServeVNC(w http.ResponseWriter, r *http.Request)

ServeVNC bridges the /browser/vnc WebSocket (noVNC, binary frames) to x11vnc on localhost, starting the browser if needed.

func (*Browser) Start

func (b *Browser) Start(ctx context.Context, width, height int32, url string) (*devboxv1.BrowserInfo, error)

Start starts Xvfb, x11vnc and Chromium if they aren't running.

func (*Browser) Stop

func (b *Browser) Stop() *devboxv1.BrowserInfo

Stop stops the browser stack.

func (*Browser) Streams

func (b *Browser) Streams() int

Streams is the number of open VNC/CDP/preview streams.

type Options

type Options struct {
	Chromium string
	Xvfb     string
	X11VNC   string
	Display  string
	// CDPPort is the localhost port agents connect to; the daemon proxies it to Chromium's own port (CDPPort+1)
	// so the first connection can start the browser.
	CDPPort     int
	VNCPort     int
	ProfileDir  string
	ExtraFlags  []string
	IdleTimeout time.Duration
	Env         func() []string
	Supervisor  *proc.Supervisor
	Clock       clock.Clock
	Log         *slog.Logger
}

Options configure a Browser.

type PreviewProxy

type PreviewProxy struct {
	// Deny are ports that must not be proxied (the daemon's own listener).
	Deny map[int]bool
	// Activity is told about proxied traffic (idle detection).
	Activity *Browser
}

PreviewProxy serves /preview/<port>/* by reverse-proxying to 127.0.0.1:<port> (WebSockets included).

func (*PreviewProxy) ServeHTTP

func (p *PreviewProxy) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler.

Jump to

Keyboard shortcuts

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