browserctl

package
v1.5.123 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 14 Imported by: 0 modules, 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 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

View Source
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

func IsConnectionRefused(err error) bool

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

func Dial(socket string) (*Client, error)

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) Info

func (c *Client) Info(ctx context.Context) (Info, error)

Info discovers the browser's identity, tabs and capabilities.

func (*Client) Quit added in v1.5.3

func (c *Client) Quit(ctx context.Context) error

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

func (c *Client) Screenshot(ctx context.Context, fullPage bool) ([]byte, error)

Screenshot returns the active tab's viewport as PNG.

func (*Client) ScreenshotTarget added in v1.5.62

func (c *Client) ScreenshotTarget(ctx context.Context, target Target) ([]byte, Meta, error)

ScreenshotTarget captures a specific tab without changing the browser's globally active tab. Unlike /v1/screenshot, the typed action accepts a target.

func (*Client) ScreenshotTargetPage added in v1.5.62

func (c *Client) ScreenshotTargetPage(ctx context.Context, target Target, fullPage bool) ([]byte, Meta, error)

ScreenshotTargetPage captures the viewport or complete page of a pinned tab.

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.

func (*Error) Error

func (e *Error) Error() string

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

func (info Info) HasCapability(name string) bool

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

func Foreground(info Info) (Tab, error)

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.

type Target

type Target struct {
	BrowserID string `json:"browserId,omitempty"`
	TabID     string `json:"tabId,omitempty"`
	TargetID  string `json:"targetId,omitempty"`
}

Target pins one tab. The browser refuses an action whose ids do not match.

Jump to

Keyboard shortcuts

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