Documentation
¶
Index ¶
- Variables
- func BrowserWebSocketURL(ctx context.Context, versionURL string) (string, error)
- func DispatchStartURL(ctx context.Context, devtoolsURL, url string) error
- func DispatchStartURLAndWait(ctx context.Context, devtoolsURL, navigationURL, destination string) error
- type BrowserVersion
- type Client
- func (c *Client) Close() error
- func (c *Client) CountPageTargets(ctx context.Context) (int, error)
- func (c *Client) Done() <-chan struct{}
- func (c *Client) Events() <-chan Message
- func (c *Client) GetBrowserVersion(ctx context.Context) (*BrowserVersion, error)
- func (c *Client) GetExtensions(ctx context.Context) ([]ExtensionInfo, error)
- func (c *Client) GetHistograms(ctx context.Context, query string) ([]Histogram, error)
- func (c *Client) GetWindowBounds(ctx context.Context) (WindowBounds, error)
- func (c *Client) IsClosed() bool
- func (c *Client) LoadUnpackedExtension(ctx context.Context, path string) (string, error)
- func (c *Client) Send(ctx context.Context, method string, params any, sessionID string) (json.RawMessage, error)
- func (c *Client) SetDeviceMetricsOverride(ctx context.Context, width, height int) error
- func (c *Client) SetWindowBoundsMaximized(ctx context.Context) error
- type Error
- type ExtensionInfo
- type Histogram
- type HistogramBucket
- type Message
- type WindowBounds
Constants ¶
This section is empty.
Variables ¶
var ErrOutcomeUnknown = errors.New("CDP command outcome is unknown")
ErrOutcomeUnknown means a CDP connection closed while a command was in flight, so the caller cannot know whether Chromium applied it.
Functions ¶
func BrowserWebSocketURL ¶
BrowserWebSocketURL reads Chrome's browser-level DevTools WebSocket URL.
func DispatchStartURL ¶
DispatchStartURL closes extra page targets and dispatches a navigation on the first page target. It does not wait for lifecycle events; Chrome owns the eventual navigation result.
Types ¶
type BrowserVersion ¶
type BrowserVersion struct {
ProtocolVersion string `json:"protocolVersion"`
Product string `json:"product"`
Revision string `json:"revision"`
UserAgent string `json:"userAgent"`
JsVersion string `json:"jsVersion"`
}
BrowserVersion is the result of a Browser.getVersion CDP call.
We use this struct only to confirm a successful round-trip; callers that just need a liveness probe can ignore the fields. The protocol-version fields are populated for convenience.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client maintains one browser-level DevTools connection. Commands may be sent concurrently. Clients created by DialWithEvents also expose protocol events through Events.
func Dial ¶
Dial opens a command-only DevTools connection. Protocol events are discarded, preserving the behavior expected by existing short-lived users.
func DialWithEvents ¶
DialWithEvents opens a DevTools connection that delivers protocol events in receive order through Events.
func (*Client) CountPageTargets ¶
CountPageTargets returns the number of open page targets.
func (*Client) Done ¶
func (c *Client) Done() <-chan struct{}
Done closes when the connection shuts down.
func (*Client) Events ¶
Events returns the event stream for clients created by DialWithEvents. It returns nil for command-only clients.
func (*Client) GetBrowserVersion ¶
func (c *Client) GetBrowserVersion(ctx context.Context) (*BrowserVersion, error)
GetBrowserVersion sends Browser.getVersion on the browser-level DevTools endpoint. It is a cheap CDP round-trip that proves the WebSocket is connected to a live, CDP-responsive Chromium browser process.
Callers should use this after Dial as a readiness gate: a successful websocket.Dial alone is not enough because a dial can complete against a half-open socket of a killed Chromium, or against a freshly bound TCP listener of a Chromium that has not yet wired up its CDP routes. A Browser.getVersion round-trip rules out both cases.
func (*Client) GetExtensions ¶
func (c *Client) GetExtensions(ctx context.Context) ([]ExtensionInfo, error)
GetExtensions returns all unpacked extensions known to Chromium.
func (*Client) GetHistograms ¶
GetHistograms sends Browser.getHistograms, a browser-level command that reads Chrome's in-memory UMA histograms without attaching to any page. query is a substring filter on the histogram name; empty returns all.
func (*Client) GetWindowBounds ¶
func (c *Client) GetWindowBounds(ctx context.Context) (WindowBounds, error)
GetWindowBounds queries the OS window bounds for the first page target via Browser.getWindowForTarget. It's a one-shot read; callers that need to wait for the WM to settle should poll this.
func (*Client) LoadUnpackedExtension ¶
LoadUnpackedExtension installs an unpacked extension from an absolute path visible to Chromium and returns its extension ID.
func (*Client) Send ¶
func (c *Client) Send(ctx context.Context, method string, params any, sessionID string) (json.RawMessage, error)
Send sends a CDP command and waits for its matching response.
func (*Client) SetDeviceMetricsOverride ¶
SetDeviceMetricsOverride sets the viewport dimensions on the first page target found in the browser. It attaches to the target with a flattened session, sends Emulation.setDeviceMetricsOverride, then detaches.
func (*Client) SetWindowBoundsMaximized ¶
SetWindowBoundsMaximized puts the OS window backing the first page target into the maximized state via Browser.setWindowBounds. It is idempotent — invoking it on a window already in maximized state is a no-op.
A mutter-managed window in maximized state auto-tracks RANDR resizes (the WM reflows it to fill the new root). So after a display resize the server only has to make sure the window is in maximized state; mutter does the rest. This replaces the prior approach of restarting chromium so it could re-apply --start-maximized.
We intentionally avoid the explicit-bounds form of setWindowBounds ({left, top, width, height} with windowState:"normal"): once a window is in normal state it stops auto-tracking subsequent RANDR events.
type ExtensionInfo ¶
type ExtensionInfo struct {
ID string `json:"id"`
Name string `json:"name"`
Version string `json:"version"`
Path string `json:"path"`
Enabled bool `json:"enabled"`
}
ExtensionInfo describes an unpacked extension known to Chromium.
type Histogram ¶
type Histogram struct {
Name string `json:"name"`
Sum int64 `json:"sum"`
Count int64 `json:"count"`
Buckets []HistogramBucket `json:"buckets"`
}
Histogram is a snapshot of a Chrome UMA histogram as returned by Browser.getHistograms. Values are cumulative since browser start and the units follow the UMA definition of the histogram (PageLoad timings are milliseconds). Only buckets with at least one sample are present.
type HistogramBucket ¶
type HistogramBucket struct {
Low int64 `json:"low"`
High int64 `json:"high"`
Count int64 `json:"count"`
}
HistogramBucket is a [Low, High) bucket of a Histogram.
type Message ¶
type Message struct {
ID int64 `json:"id,omitempty"`
Method string `json:"method,omitempty"`
Params json.RawMessage `json:"params,omitempty"`
Result json.RawMessage `json:"result,omitempty"`
Error *Error `json:"error,omitempty"`
SessionID string `json:"sessionId,omitempty"`
}
Message is a response or event received from Chromium.
type WindowBounds ¶
WindowBounds is the subset of Browser.getWindowBounds CDP returns that callers care about. For maximized/fullscreen windows the width/height fields reflect the live window size (which the WM aligns with the X root); for normal-state windows they reflect the saved-restore bounds.