cdp

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: MPL-2.0 Imports: 8 Imported by: 0 modules, 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

Overview

Package cdp provides a minimal Chrome DevTools Protocol client.

Index

Constants

View Source
const DefaultTimeout = 60 * time.Second

DefaultTimeout is the default timeout for CDP commands.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is a CDP protocol client.

func Dial

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

Dial connects to a CDP endpoint and returns a new client.

func NewClient

func NewClient(conn Conn) *Client

NewClient creates a new CDP client with the given connection.

func (*Client) Close

func (c *Client) Close() error

Close closes the client connection and stops the read loop.

func (*Client) Err

func (c *Client) Err() error

Err returns any error that caused the client to close.

func (*Client) Send

func (c *Client) Send(method string, params interface{}) (json.RawMessage, error)

Send sends a CDP command and waits for the response. Uses the default timeout.

func (*Client) SendContext

func (c *Client) SendContext(ctx context.Context, method string, params interface{}) (json.RawMessage, error)

SendContext sends a CDP command with a context for cancellation.

func (*Client) SendToSession

func (c *Client) SendToSession(ctx context.Context, sessionID string, method string, params interface{}) (json.RawMessage, error)

SendToSession sends a CDP command to a specific session. If sessionID is empty, the command is sent to the browser-level target.

func (*Client) Subscribe

func (c *Client) Subscribe(method string, handler func(Event))

Subscribe registers a handler for CDP events matching the given method. Multiple handlers can be registered for the same method.

type Conn

type Conn interface {
	// Read reads a message from the connection.
	// Returns message type, payload, and any error.
	Read(ctx context.Context) (websocket.MessageType, []byte, error)

	// Write writes a message to the connection.
	Write(ctx context.Context, typ websocket.MessageType, p []byte) error

	// Close closes the connection with a status code and reason.
	Close(code websocket.StatusCode, reason string) error
}

Conn defines the interface for a WebSocket connection. This abstraction enables testing with mock connections.

type Error

type Error struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Data    string `json:"data,omitempty"`
}

Error represents a CDP protocol error.

func (*Error) Error

func (e *Error) Error() string

Error implements the error interface.

type Event

type Event struct {
	Method    string          `json:"method"`
	Params    json.RawMessage `json:"params"`
	SessionID string          `json:"sessionId,omitempty"`
}

Event represents a CDP event notification.

type Request

type Request struct {
	ID        int64       `json:"id"`
	Method    string      `json:"method"`
	Params    interface{} `json:"params,omitempty"`
	SessionID string      `json:"sessionId,omitempty"`
}

Request represents a CDP command request.

type Response

type Response struct {
	ID     int64           `json:"id"`
	Result json.RawMessage `json:"result,omitempty"`
	Error  *Error          `json:"error,omitempty"`
}

Response represents a CDP command response.

Jump to

Keyboard shortcuts

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