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 ¶
- func ValidateNavigateURL(rawURL string) error
- type Client
- func (c *Client) Click(selector string) error
- func (c *Client) Close() error
- func (c *Client) Eval(expr string) (string, error)
- func (c *Client) HTML() (string, error)
- func (c *Client) Navigate(url string, timeout time.Duration) error
- func (c *Client) Screenshot() (string, error)
- func (c *Client) Text() (string, error)
- func (c *Client) Title() (string, error)
- func (c *Client) Type(selector, text string) error
- func (c *Client) URL() (string, error)
- func (c *Client) WaitSelector(selector string, timeout time.Duration) error
- type Command
- type Result
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ValidateNavigateURL ¶
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 NewClient ¶
NewClient wraps an already-connected DevTools WebSocket and starts its read loop. Exported so tests can supply a fake CDP server.
func (*Client) Click ¶
Click finds selector and dispatches a click. Implemented via Runtime.evaluate to avoid depending on the DOM/Input CDP domains.
func (*Client) Eval ¶
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) Navigate ¶
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 ¶
Screenshot captures the current viewport as a base64-encoded PNG.
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.