browserctl

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 12 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 kitty-browse 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.

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

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

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

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

func (*Client) Screenshot

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

Screenshot returns the active tab's viewport as PNG.

type Error

type Error struct {
	Code      string          `json:"code"`
	Message   string          `json:"message"`
	Retryable bool            `json:"retryable"`
	Details   json.RawMessage `json:"details,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 Info

type Info struct {
	APIVersion   string       `json:"apiVersion"`
	BrowserID    string       `json:"browserId"`
	ActiveTabID  string       `json:"activeTabId"`
	Backend      string       `json:"backend"`
	Tabs         []Tab        `json:"tabs"`
	Capabilities []Capability `json:"capabilities"`
}

Info is /v1/info.

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 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.

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