cdp

package
v0.61.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 16 Imported by: 1 module, 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

Index

Constants

View Source
const DefaultStartTimeout = 30 * time.Second

DefaultStartTimeout is the default timeout for launching the headless Chrome process.

Variables

This section is empty.

Functions

func FindChromeBinary

func FindChromeBinary() (string, error)

FindChromeBinary locates a Chrome or Chromium executable from CHROME_BIN or standard PATH names.

Types

type Browser

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

Browser manages a headless Chrome process and its Chrome DevTools Protocol page endpoint.

func NewBrowserFromPageWSURL

func NewBrowserFromPageWSURL(pageWSURL string) *Browser

NewBrowserFromPageWSURL creates a Browser targeting an existing CDP page WebSocket endpoint without managing a process.

func StartBrowser

func StartBrowser(ctx context.Context) (*Browser, error)

StartBrowser launches a headless Chrome process immediately and resolves its initial page WebSocket URL.

func (*Browser) Close

func (b *Browser) Close() error

Close terminates the headless Chrome process and removes its temporary profile directory.

func (*Browser) DialPage

func (b *Browser) DialPage(ctx context.Context) (*Client, error)

DialPage connects a new CDP Client to the browser's page target.

type Client

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

Client manages a single Chrome DevTools Protocol WebSocket connection.

func Dial

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

Dial establishes a new Chrome DevTools Protocol WebSocket client connection to wsURL.

func (*Client) CapturePNGScreenshot

func (c *Client) CapturePNGScreenshot(ctx context.Context) ([]byte, error)

CapturePNGScreenshot captures a PNG screenshot of the current page and returns the decoded PNG bytes.

func (*Client) Close

func (c *Client) Close() error

Close closes the underlying WebSocket connection.

func (*Client) Evaluate

func (c *Client) Evaluate(ctx context.Context, expression string, awaitPromise bool, out any) error

Evaluate executes a JavaScript expression via Runtime.evaluate and decodes the returned value into out.

func (*Client) Navigate

func (c *Client) Navigate(ctx context.Context, url string) error

Navigate enables the Page and Runtime domains and navigates the page to url.

func (*Client) SetViewportSize

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

SetViewportSize overrides the browser device metrics with the specified viewport width and height.

type TransportError

type TransportError struct {
	// Err is the underlying WebSocket transport error.
	Err error
}

TransportError wraps WebSocket send and receive failures so callers can distinguish unrecoverable connection errors from transient CDP protocol or JavaScript evaluation errors.

func (*TransportError) Error

func (e *TransportError) Error() string

Error returns the string representation of the underlying transport error.

func (*TransportError) Unwrap

func (e *TransportError) Unwrap() error

Unwrap returns the underlying transport error for errors.Is and errors.As checks.

Jump to

Keyboard shortcuts

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