browser

package
v0.6.15-beta Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package browser manages optional, externally installed Chrome processes for runner workspaces.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AssetChunk

type AssetChunk struct {
	Data        []byte `json:"data"`
	ContentType string `json:"contentType"`
	EOF         bool   `json:"eof"`
}

AssetChunk is a bounded portion of one trusted DevTools frontend file.

type Config

type Config struct {
	// Executable is an installed Chrome/Chromium executable or PATH name. Blank disables launching.
	Executable string
	// DevToolsDir optionally contains a compiled frontend compatible with the installed browser version.
	// These trusted assets are never downloaded or embedded by this package.
	DevToolsDir string
	// IdleTimeout applies only to sessions without attachments. Nonpositive values use fifteen minutes.
	IdleTimeout time.Duration
}

Config is trusted runner configuration, not workspace- or page-provided input.

type Info

type Info struct {
	SessionID      string `json:"sessionId"`
	ConversationID string `json:"conversationId"`
	CWD            string `json:"cwd"`
	DevTools       bool   `json:"devTools"`
}

Info identifies one immutable browser session. DevTools indicates a configured frontend directory.

type Manager

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

Manager owns at most four conversation sessions, independently of individual agent runs. Call Close at runner shutdown. Connections must be released even if their socket has already closed.

func NewManager

func NewManager(ctx context.Context, config Config) *Manager

NewManager creates a lazy manager. It does not launch a browser or inspect a user profile.

func (*Manager) Close

func (m *Manager) Close() error

Close stops all sessions and waits for subprocess and temporary-profile cleanup.

func (*Manager) Command

func (m *Manager) Command(ctx context.Context, scope Scope, method string, params json.RawMessage) (json.RawMessage, error)

Command opens or reuses a session and sends one CDP command over its own page connection. It returns the command's result (not the envelope), ignoring events and unrelated response IDs. Methods are not allowlisted: authorization belongs to the caller, as it does for Connect.

func (*Manager) Connect

func (m *Manager) Connect(ctx context.Context, scope Scope, sessionID string) (*websocket.Conn, func(), error)

Connect attaches to an existing page target, never creating a session for a stale ID. The idempotent release function closes the socket and releases its idle-timeout lease. Canceling ctx, stopping the session, or closing the manager also closes the socket.

func (*Manager) Enabled

func (m *Manager) Enabled() bool

Enabled reports whether an executable is configured, not whether it has successfully launched.

func (*Manager) Open

func (m *Manager) Open(ctx context.Context, scope Scope) (Info, error)

Open opens or reuses a conversation session. Concurrent opens within a scope share one startup. Canceling the initiating request during startup tears down that startup; after success, request cancellation does not affect the browser lifetime.

func (*Manager) ReadAsset

func (m *Manager) ReadAsset(path string, offset int64) (AssetChunk, error)

ReadAsset reads at most 128 KiB from a relative frontend path. Files larger than 16 MiB, non-regular files, unsupported extensions, and paths/symlinks escaping DevToolsDir are rejected.

func (*Manager) Stop

func (m *Manager) Stop(scope Scope, sessionID string) error

Stop closes one exact session and all of its attached sockets. Stale IDs cannot stop replacements.

type Scope

type Scope struct {
	ConversationID string
	CWD            string
}

Scope isolates a conversation's browser in one canonical working directory.

Jump to

Keyboard shortcuts

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