Documentation
¶
Overview ¶
Package browserctl talks to a running browser over its owner-only Unix-domain control socket. It is the typed client the browser tool uses: /v1/info for discovery, /v1/actions for one action, /v1/screenshot for a picture, and /v1/quit for a graceful shutdown.
The socket file's mode is the access control. A socket another user can write is refused rather than used, because an action puts input into a real browser session.
Index ¶
- Constants
- func IsConnectionRefused(err error) bool
- func SocketFromEnv() string
- type Capability
- type Client
- func (c *Client) Action(ctx context.Context, action string, params any, target Target, ...) (json.RawMessage, Meta, error)
- func (c *Client) CloseIdleConnections()
- func (c *Client) Info(ctx context.Context) (Info, error)
- func (c *Client) Quit(ctx context.Context) error
- func (c *Client) Screenshot(ctx context.Context, fullPage bool) ([]byte, error)
- func (c *Client) ScreenshotTarget(ctx context.Context, target Target) ([]byte, Meta, error)
- func (c *Client) ScreenshotTargetPage(ctx context.Context, target Target, fullPage bool) ([]byte, Meta, error)
- type Error
- type ExplicitSelection
- type Info
- type Meta
- type QuitResult
- type Tab
- type Target
Constants ¶
const ( // EnvSocket is the control socket path a kitty-browse pane exposes. EnvSocket = "KITTY_BROWSE_SOCKET" // APIVersion is the only contract this client speaks. APIVersion = "v1" // CapQuit is the advertised capability for /v1/quit. A browser that does // not advertise it predates the endpoint; asking anyway would be a guess. CapQuit = "quit" )
Variables ¶
This section is empty.
Functions ¶
func IsConnectionRefused ¶
IsConnectionRefused reports whether err means the browser is gone, so a tool can say that instead of printing a socket error.
func SocketFromEnv ¶
func SocketFromEnv() string
SocketFromEnv returns the configured control socket, or "".
Types ¶
type Capability ¶
type Capability struct {
Name string `json:"name"`
Description string `json:"description"`
ReadOnly bool `json:"readOnly"`
InputSchema json.RawMessage `json:"inputSchema"`
}
Capability is one action the browser implements, with its input schema.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is one browser's control socket.
func Dial ¶
Dial validates the socket and returns a client. It does not call the browser: a caller that wants to prove it is alive calls Info.
func NewWithTransport ¶
func NewWithTransport(socket string, rt http.RoundTripper) *Client
NewWithTransport builds a client for an already-trusted connection: a nil transport dials the Unix socket, and a test or embedder may supply its own. It skips the socket-permission check, which only Dial can make.
func (*Client) Action ¶
func (c *Client) Action(ctx context.Context, action string, params any, target Target, timeout time.Duration) (json.RawMessage, Meta, error)
Action runs one typed action against one target tab.
func (*Client) CloseIdleConnections ¶ added in v1.5.1
func (c *Client) CloseIdleConnections()
CloseIdleConnections releases pooled connections after a discovery probe.
func (*Client) Quit ¶ added in v1.5.3
Quit asks the browser to shut down normally: it flushes its profile, closes the page and removes its own control socket. It must only be called on an endpoint the caller has already identified (see the pane close path), because a quit aimed at the wrong browser is as destructive as a stray click.
func (*Client) Screenshot ¶
Screenshot returns the active tab's viewport as PNG.
func (*Client) ScreenshotTarget ¶ added in v1.5.62
ScreenshotTarget captures a specific tab without changing the browser's globally active tab. Unlike /v1/screenshot, the typed action accepts a target.
type Error ¶
type Error struct {
Code string `json:"code"`
Message string `json:"message"`
Retryable bool `json:"retryable"`
Details json.RawMessage `json:"details,omitempty"`
ExecutionState string `json:"executionState,omitempty"`
Phase string `json:"phase,omitempty"`
}
Error is the action-level failure. OK false with a code is the branch to read; HTTP status alone is not enough.
type ExplicitSelection ¶ added in v1.5.62
type ExplicitSelection struct {
Revision uint64 `json:"revision"`
TabID string `json:"tabId"`
TargetID string `json:"targetId"`
}
ExplicitSelection records the most recent successful control-API tab activation, with a monotonic revision for one browser instance.
type Info ¶
type Info struct {
APIVersion string `json:"apiVersion"`
BrowserID string `json:"browserId"`
LoginProfile string `json:"loginProfile,omitempty"`
ActiveTabID string `json:"activeTabId"`
Backend string `json:"backend"`
Tabs []Tab `json:"tabs"`
Capabilities []Capability `json:"capabilities"`
ExplicitSelection *ExplicitSelection `json:"explicitSelection,omitempty"`
}
Info is /v1/info.
func (Info) HasCapability ¶ added in v1.5.3
HasCapability reports whether the browser advertises one action. Callers use it to decide whether an endpoint can do something at all, instead of sending a request and interpreting "unknown_action".
type Meta ¶
type Meta struct {
BrowserID string `json:"browserId"`
TabID string `json:"tabId"`
TargetID string `json:"targetId"`
URL string `json:"url"`
Title string `json:"title"`
Backend string `json:"backend"`
}
Meta is what the browser reports about where the action ran.
type QuitResult ¶ added in v1.5.3
type QuitResult struct {
Quitting bool `json:"quitting"`
}
QuitResult is /v1/quit's result: the browser accepted the request and is unwinding. It is not a promise that the process has exited yet, which is why a close waits for window-exit as well.
type Tab ¶
type Tab struct {
ID string `json:"id"`
TargetID string `json:"targetId"`
URL string `json:"url"`
Title string `json:"title"`
Index int `json:"index"`
Active bool `json:"active"`
}
Tab is one browser tab with its stable ids.
func Foreground ¶ added in v1.5.71
Foreground is the single default-target rule for Agent and GUI. Only the conversation host's actual foreground is eligible; another safe background tab is not a substitute for a missing, closed or unsupported foreground.