cdpclient

package
v0.0.0-...-452f342 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DispatchStartURL

func DispatchStartURL(ctx context.Context, devtoolsURL, url string) error

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 is a minimal CDP client that communicates over a browser-level DevTools WebSocket connection.

func Dial

func Dial(ctx context.Context, devtoolsURL string) (*Client, error)

Dial opens a WebSocket connection to the given DevTools URL.

func (*Client) Close

func (c *Client) Close() error

Close shuts down the WebSocket connection.

func (*Client) CountPageTargets

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

CountPageTargets returns the number of open page targets.

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

func (c *Client) GetHistograms(ctx context.Context, query string) ([]Histogram, error)

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

func (c *Client) SetDeviceMetricsOverride(ctx context.Context, width, height int) error

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

func (c *Client) SetWindowBoundsMaximized(ctx context.Context) error

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

type WindowBounds struct {
	WindowID    int
	Width       int
	Height      int
	WindowState string
}

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.

Jump to

Keyboard shortcuts

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