cdp

package
v0.4.12 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package cdp is a minimal Chrome DevTools Protocol client over --remote-debugging-pipe: JSON messages, each followed by a NUL byte, the browser reading fd 3 and writing fd 4.

The pipe rather than --remote-debugging-port, for two reasons: no other local process can connect and drive the browser, and Chrome offers some domains only to a pipe client.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

type Conn struct {

	// Timeout bounds every Call. Default 30s.
	Timeout time.Duration
	// contains filtered or unexported fields
}

Conn is a connection to one browser.

func New

func New(w io.Writer, r io.Reader, onEvent func(*Msg)) *Conn

New reads replies and events from r and writes commands to w. onEvent runs on the reading goroutine, in order: a handler that calls back into the browser must do it on a goroutine of its own.

func (*Conn) Call

func (c *Conn) Call(session, method string, params any) (json.RawMessage, error)

Call sends method to the session ("" = the browser) and waits for its result.

func (*Conn) Closed

func (c *Conn) Closed() <-chan struct{}

Closed is closed once the browser's end of the pipe is.

func (*Conn) Eval

func (c *Conn) Eval(session, js string) (json.RawMessage, error)

Eval runs JS in a page and returns its value as JSON (promises awaited).

type Error

type Error struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

Error is a protocol error reply.

func (*Error) Error

func (e *Error) Error() string

type Msg

type Msg 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"`
}

Msg is one protocol message: a reply (ID set) or an event (Method set).

Jump to

Keyboard shortcuts

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