Documentation
¶
Overview ¶
Package browser manages optional, externally installed Chrome processes for runner workspaces.
Index ¶
- type AssetChunk
- type Config
- type Connection
- type Info
- type Manager
- func (m *Manager) Acquire(ctx context.Context, scope Scope) (Connection, func(), error)
- func (m *Manager) Close() error
- func (m *Manager) Command(ctx context.Context, scope Scope, method string, params json.RawMessage) (json.RawMessage, error)
- func (m *Manager) Connect(ctx context.Context, scope Scope, sessionID string) (*websocket.Conn, func(), error)
- func (m *Manager) Enabled() bool
- func (m *Manager) HasConversation(conversationID string) bool
- func (m *Manager) Open(ctx context.Context, scope Scope) (Info, error)
- func (m *Manager) ReadAsset(path string, offset int64) (AssetChunk, error)
- func (m *Manager) Stop(scope Scope, sessionID string) error
- func (m *Manager) StopConversation(conversationID string) error
- type Scope
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 Connection ¶
type Connection struct {
SessionID string `json:"sessionId"`
CDPURL string `json:"cdpUrl"`
PageTargetID string `json:"pageTargetId"`
}
Connection identifies a runner-local browser CDP endpoint and the shared page. Direct clients have browser-wide access; the target ID is not an access restriction.
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 ¶
NewManager creates a lazy manager. It does not launch a browser or inspect a user profile.
func (*Manager) Acquire ¶
Acquire opens or reuses the shared browser and leases its runner-local CDP endpoint. Authorization belongs to the caller. Release is idempotent and does not stop Chrome or disconnect direct clients. The lease also ends when ctx or the browser is canceled.
func (*Manager) Close ¶
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 ¶
Enabled reports whether an executable is configured, not whether it has successfully launched.
func (*Manager) HasConversation ¶
HasConversation reports whether the conversation still owns a session, including a session that is starting or being cleaned up.
func (*Manager) Open ¶
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 ¶
Stop closes one exact session and all of its attached sockets. Stale IDs cannot stop replacements.
func (*Manager) StopConversation ¶
StopConversation stops all sessions for an exact conversation ID, including attached or starting sessions, and waits for process/profile cleanup. It does not resolve directories, which may no longer exist. Callers must serialize session creation with this operation if the conversation must stay discarded.