browser

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package browser defines the wire contract between the runeward control plane and the in-sandbox browser driver (cmd/runeward-browser), plus a minimal Chrome DevTools Protocol client used by the driver. Each driver call carries exactly one Command and receives exactly one Result.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateNavigateURL

func ValidateNavigateURL(rawURL string) error

ValidateNavigateURL enforces safe browser navigation targets.

Types

type Client

type Client struct {

	// CallTimeout overrides defaultCallTimeout when non-zero.
	CallTimeout time.Duration
	// contains filtered or unexported fields
}

Client is a minimal Chrome DevTools Protocol client for a single page-level DevTools WebSocket. Calls are matched to responses by id; unsolicited events go to one-shot subscribers. A single background read loop demultiplexes the socket. Intended for sequential use from one goroutine.

func Dial

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

Dial connects a Client to a page-level DevTools WebSocket URL.

func NewClient

func NewClient(conn *websocket.Conn) *Client

NewClient wraps an already-connected DevTools WebSocket and starts its read loop. Exported so tests can supply a fake CDP server.

func (*Client) Click

func (c *Client) Click(selector string) error

Click finds selector and dispatches a click. Implemented via Runtime.evaluate to avoid depending on the DOM/Input CDP domains.

func (*Client) Close

func (c *Client) Close() error

Close closes the connection, which also stops the read loop.

func (*Client) Eval

func (c *Client) Eval(expr string) (string, error)

Eval runs expr via Runtime.evaluate and returns the value as a string. Strings come back verbatim; other values as their JSON encoding.

func (*Client) HTML

func (c *Client) HTML() (string, error)

HTML returns the full serialized document.

func (*Client) Navigate

func (c *Client) Navigate(url string, timeout time.Duration) error

Navigate enables the Page domain, navigates to url, and waits up to timeout for Page.loadEventFired. A load-wait timeout is not fatal (the page is often still usable), so Navigate returns nil in that case.

func (*Client) Screenshot

func (c *Client) Screenshot() (string, error)

Screenshot captures the current viewport as a base64-encoded PNG.

func (*Client) Text

func (c *Client) Text() (string, error)

Text returns document.body.innerText (or "" when there is no body).

func (*Client) Title

func (c *Client) Title() (string, error)

Title returns document.title.

func (*Client) Type

func (c *Client) Type(selector, text string) error

Type focuses selector, sets its value, and dispatches input/change events so frameworks observe the change.

func (*Client) URL

func (c *Client) URL() (string, error)

URL returns the current location.href.

func (*Client) WaitSelector

func (c *Client) WaitSelector(selector string, timeout time.Duration) error

WaitSelector polls until an element matching selector exists or timeout elapses.

type Command

type Command struct {
	// Action selects the operation: navigate|eval|text|html|screenshot|
	// click|type|wait|title|url|close|ping.
	Action    string `json:"action"`
	Token     string `json:"token,omitempty"`
	URL       string `json:"url,omitempty"`
	Selector  string `json:"selector,omitempty"`
	Expr      string `json:"expr,omitempty"`       // JS source for action=eval
	Text      string `json:"text,omitempty"`       // text to type for action=type
	TimeoutMS int    `json:"timeout_ms,omitempty"` // 0 means driver default
}

Command is a single browser action requested over the driver's control socket. Exactly one Command is written per connection.

type Result

type Result struct {
	OK    bool   `json:"ok"`
	Error string `json:"error,omitempty"`
	// Value is the textual payload (eval result, text, html, title, url).
	Value string `json:"value,omitempty"`
	// Screenshot is a base64 PNG for action=screenshot.
	Screenshot string `json:"screenshot,omitempty"`
}

Result is the driver's reply to a Command. Exactly one Result is written per connection.

Jump to

Keyboard shortcuts

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