browserhost

package
v0.2.19 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 26 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 browserhost runs one headless Chromium behind the same native control API the visible pane serves: /v1/info, /v1/actions, /v1/screenshot and /v1/quit on an owner-only Unix socket.

It exists for hosts such as golder that want the browser without a terminal pane. Action semantics are not reimplemented: page actions run through internal/action and host-managed actions through internal/host, the same code paths the visible browsepane uses. The pane remains the primary integration.

Index

Constants

View Source
const SharedProtocol = "kitty-browse-views-v1"

Variables

This section is empty.

Functions

func RuntimePolicyDigest added in v0.2.12

func RuntimePolicyDigest(opts Options) string

RuntimePolicyDigest identifies the broker's immutable execution configuration, not any embedding application's permission decision or outer OS sandbox.

func ServeShared added in v0.2.11

func ServeShared(ctx context.Context, opts SharedOptions) error

ServeShared runs a single profile owner. Its advisory runtime lock prevents concurrent starts; normal shutdown flushes the profile after closing views.

func SharedReady added in v0.2.11

func SharedReady(ctx context.Context, runtimeDir string) bool

func SharedSocket added in v0.2.11

func SharedSocket(dir string) string

SharedSocket returns the hub endpoint. Unix keeps the historical short path.

func ViewID added in v0.2.11

func ViewID(conversation, instance string) string

ViewID binds a conversation and an optional independently opened instance.

func ViewSocket added in v0.2.11

func ViewSocket(dir, id string) string

ViewSocket returns one conversation's control endpoint.

Types

type ContinueRequest added in v0.2.12

type ContinueRequest = host.ContinueRequest

type Host

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

Host is one running headless browser.

func Start

func Start(ctx context.Context, opts Options) (*Host, error)

Start launches Chromium, opens the first page and starts serving the control API. It returns once the socket is listening; page load failures leave Chromium's error page and the socket alive, exactly like the pane.

func (*Host) Close

func (h *Host) Close() error

Close asks the browser to quit and returns once it has.

func (*Host) ContinueChecked added in v0.2.12

func (h *Host) ContinueChecked(ctx context.Context, req ContinueRequest) error

func (*Host) OperatorAction added in v0.2.11

func (h *Host) OperatorAction(ctx context.Context, raw json.RawMessage) (json.RawMessage, error)

OperatorAction lets a trusted surface use browser chrome while automation is paused. This closed set has no scripts, file access or arbitrary page actions. It is intentionally absent from /v1/actions and requires a private capability when called through the shared host's separate management socket.

func (*Host) SendOperatorInput added in v0.2.9

func (h *Host) SendOperatorInput(ctx context.Context, event OperatorInput) error

SendOperatorInput delivers an input from a trusted, locally authenticated operator surface. This is deliberately an in-process API, not a socket action. Embedders must authenticate remote surfaces before calling it; merely possessing the ordinary browser control socket is not sufficient authority. It leaves an automation pause in place and never retries a rejected action.

func (*Host) SendOperatorInputJSON added in v0.2.9

func (h *Host) SendOperatorInputJSON(ctx context.Context, raw []byte) error

SendOperatorInputJSON is the version-independent in-process embedding seam for SendOperatorInput. It accepts only the closed OperatorInput schema and is not registered on the control socket.

func (*Host) Socket

func (h *Host) Socket() string

Socket is the control socket path this host serves, or "".

func (*Host) Wait

func (h *Host) Wait() error

Wait blocks until the browser is asked to quit, ctx is canceled or Close is called, then releases Chromium and removes the socket. A graceful quit, and a cancelled ctx, are not errors.

type Hub added in v0.2.11

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

Hub owns one Chromium and one profile. Each view opened on it has its own browser identity, socket, tab collection, selection and operator surface. Closing a View never closes another View or the Hub's profile.

func StartHub added in v0.2.11

func StartHub(ctx context.Context, opts Options) (*Hub, error)

StartHub starts a private anchor in one Chromium using opts' profile and launch policy. The caller's context owns the hub after startup. No view or browser control socket is exposed until OpenView succeeds.

func (*Hub) Close added in v0.2.11

func (h *Hub) Close() error

Close terminates all views before releasing Chromium and its profile.

func (*Hub) OpenView added in v0.2.11

func (h *Hub) OpenView(ctx context.Context, opts ViewOptions) (*Host, error)

OpenView starts a session-local browser surface. Startup cancellation only destroys this view; it never cancels the hub or any other view.

type InteractionState added in v0.2.12

type InteractionState = host.InteractionState

type OperatorInput added in v0.2.9

type OperatorInput struct {
	BrowserID string  `json:"browserId"`
	TabID     string  `json:"tabId"`
	TargetID  string  `json:"targetId"`
	Kind      string  `json:"kind"` // pointer-down, pointer-hover, pointer-move, pointer-up, pointer-cancel, scroll, text, key
	X         float64 `json:"x,omitempty"`
	Y         float64 `json:"y,omitempty"`
	DeltaY    float64 `json:"deltaY,omitempty"`
	Text      string  `json:"text,omitempty"`
	Key       string  `json:"key,omitempty"`
}

OperatorInput is a bounded, person-originated input event for one exact tab. It intentionally does not carry a script, selector, filesystem path, or URL.

type Options

type Options struct {
	// URL is the first page to open. Empty opens https://example.com, the same
	// default the pane and the kitty-browse binary use.
	URL string
	// Socket is the owner-only Unix socket that serves the control API. Empty
	// runs the browser without one, which is useful only for a smoke test.
	Socket string
	// Chrome is the Chromium executable path. Empty searches PATH.
	Chrome string
	// ProxyServer is an explicit reviewed proxy; ambient proxy variables are not
	// used. Credentials in the proxy URL are rejected by the browser launcher.
	ProxyServer string
	// ProfileDir is a dedicated persistent profile. Empty uses kitty-browse's
	// own configuration directory.
	ProfileDir string
	// LoginProfile is an optional host-assigned identity for saved-login access
	// checks. It contains no cookie values or filesystem path.
	LoginProfile string
	// DownloadDir is where downloads are written. Empty uses the profile's
	// Downloads directory, or a temporary directory in private mode.
	DownloadDir string
	// Private uses a temporary profile and writes no state.
	Private bool
	// Stealth removes Chromium's headless UA token and automation markers. The
	// pane defaults this on, so DefaultOptions sets it; the zero value keeps
	// Chromium's native headless identity.
	Stealth bool
	// UserAgent overrides the per-target User-Agent. Empty derives it from the
	// running Chromium build, exactly like the pane.
	UserAgent string
	// ViewportWidth and ViewportHeight are the emulated page size. Zero uses
	// 1280x800. The pane always emulates the pane's own size; a headless host
	// needs one explicitly, because Chromium's default window is not a page the
	// control API can screenshot predictably.
	ViewportWidth  int
	ViewportHeight int
	// LoadTimeout bounds one page load. Zero uses 30s.
	LoadTimeout time.Duration
	// BrowserOutput receives Chromium's diagnostic output. Private mode ignores
	// it, like the pane's debug log.
	BrowserOutput io.Writer
	// Controlled embedders may require the allocator to retain Chromium's
	// native sandbox even when running as root (otherwise startup must fail).
	RequireSandbox bool
}

Options configures one headless browser.

func DefaultOptions

func DefaultOptions() Options

DefaultOptions returns the pane's defaults, so a headless host started with them behaves like a visible one.

type RemoteView added in v0.2.11

type RemoteView struct {
	Socket, BrowserID string
	// contains filtered or unexported fields
}

RemoteView is a trusted operator connection. Do not expose its credential to tools, logs or transcripts. The ordinary Socket serves automation only.

func OpenShared added in v0.2.11

func OpenShared(ctx context.Context, opts SharedOptions, id, url string) (*RemoteView, error)

OpenShared authenticates a trusted frontend and opens/reconnects only its conversation's view. The returned operator capability must remain private.

func ReconnectShared added in v0.2.11

func ReconnectShared(ctx context.Context, opts SharedOptions, id string) (*RemoteView, error)

ReconnectShared never launches, navigates, changes proxy or creates a view.

func (*RemoteView) Attest added in v0.2.12

func (v *RemoteView) Attest(ctx context.Context) (ViewAttestation, error)

func (*RemoteView) Close added in v0.2.11

func (v *RemoteView) Close() error

Close releases only this conversation's view, never the profile owner or another view. The broker exits after the last view and an idle grace period.

func (*RemoteView) ContinuationOutcome added in v0.2.12

func (v *RemoteView) ContinuationOutcome(ctx context.Context, req ContinueRequest) (string, error)

func (*RemoteView) ContinueChecked added in v0.2.12

func (v *RemoteView) ContinueChecked(ctx context.Context, req ContinueRequest) error

func (*RemoteView) KeepAlive added in v0.2.11

func (v *RemoteView) KeepAlive(ctx context.Context) func()

KeepAlive maintains this view while a frontend owns it. A crashed frontend cannot leak an immortal Chromium view: the owner expires its lease after two minutes. It never retries a failed input or opens a replacement view.

func (*RemoteView) OperatorAction added in v0.2.11

func (v *RemoteView) OperatorAction(ctx context.Context, raw json.RawMessage) (json.RawMessage, error)

func (*RemoteView) SendOperatorInput added in v0.2.11

func (v *RemoteView) SendOperatorInput(ctx context.Context, in OperatorInput) error

type Sessions added in v0.2.11

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

Sessions assigns at most one live view to each trusted conversation ID. It is an in-process registry: a cross-process broker must authenticate callers and derive IDs and socket paths before invoking it.

func NewSessions added in v0.2.11

func NewSessions(hub *Hub) *Sessions

NewSessions creates the conversation registry for one shared profile.

func (*Sessions) Open added in v0.2.11

func (s *Sessions) Open(ctx context.Context, id string, opts ViewOptions) (*Host, error)

Open returns the existing view for the same conversation and socket, or creates one. The URL is only used on creation: attaching never navigates an existing page. A canceled waiter does not cancel another caller's launch.

type SharedOptions added in v0.2.11

type SharedOptions struct {
	Browser              Options
	StateDir, RuntimeDir string
	IdleTimeout          time.Duration
}

SharedOptions is supplied only by the trusted embedder, never a page or model. StateDir holds an owner-only credential outside the agent's file boundary; RuntimeDir holds short Unix sockets. One server owns a dedicated profile.

type ViewAttestation added in v0.2.12

type ViewAttestation struct {
	ViewID              string `json:"viewId"`
	BrowserID           string `json:"browserId"`
	InstanceEpoch       string `json:"instanceEpoch"`
	Socket              string `json:"socket"`
	LoginProfile        string `json:"loginProfile"`
	ProxyMode           string `json:"proxyMode"`
	ChromiumSandbox     bool   `json:"chromiumSandbox"`
	Challenge           string `json:"challenge"`
	RuntimeEnvelope     string `json:"runtimeEnvelope"`
	RuntimePolicyDigest string `json:"runtimePolicyDigest"`
}

ViewAttestation is returned over the authenticated management connection, never by a page. It proves runtime facts, not Golder policy approval.

type ViewOptions added in v0.2.11

type ViewOptions struct {
	URL, Socket                   string
	ViewportWidth, ViewportHeight int
	LoadTimeout                   time.Duration
}

ViewOptions contains only per-view options. Chromium, profile and proxy settings belong to the Hub and cannot differ between views.

Jump to

Keyboard shortcuts

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