cdp

package
v0.16.521 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: AGPL-3.0 Imports: 14 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 carries flattened Chrome DevTools sessions over interchangeable transports.

Index

Constants

View Source
const DefaultTimeout = 10 * time.Second

DefaultTimeout bounds commands whose caller has not supplied a deadline.

View Source
const MaxMessage = 64 << 20

MaxMessage bounds a single CDP record in bytes.

Variables

View Source
var ErrClosed = errors.New("CDP connection closed")

ErrClosed indicates that the transport is no longer available.

Functions

func ReadMessage

func ReadMessage(r *bufio.Reader) ([]byte, error)

ReadMessage accepts only complete NUL-terminated records, with a bound for broken peers.

func WithTimeout

func WithTimeout(ctx context.Context) (context.Context, context.CancelFunc)

WithTimeout preserves explicit deadlines and bounds otherwise unbounded work.

Types

type Conn

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

Conn multiplexes commands and events on a single transport.

func Dial

func Dial(ctx context.Context, base string, handler EventHandler) (*Conn, error)

Dial discovers the browser endpoint at an HTTP DevTools address.

func New

func New(t Transport, handler EventHandler) *Conn

New creates a connection; Run must be started before calling commands.

func (*Conn) Call

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

Call waits for a command reply, bounded by the context or DefaultTimeout.

func (*Conn) Close

func (c *Conn) Close() error

Close interrupts all pending calls and closes the transport.

func (*Conn) Done

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

Done closes when the connection stops.

func (*Conn) Run

func (c *Conn) Run(ctx context.Context) error

Run reads replies and dispatches events until the connection closes.

func (*Conn) Send

func (c *Conn) Send(ctx context.Context, method string, params any, session string) error

Send writes a command without waiting for its reply, for flow-control acknowledgements.

type EventHandler

type EventHandler func(method, session string, params json.RawMessage)

EventHandler runs on the reader goroutine; it must never wait for a CDP reply.

type Socket

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

Socket carries CDP messages over a WebSocket.

func (*Socket) Close

func (s *Socket) Close() error

Close interrupts the WebSocket connection.

func (*Socket) Read

func (s *Socket) Read(ctx context.Context) ([]byte, error)

Read receives one CDP WebSocket message.

func (*Socket) Write

func (s *Socket) Write(ctx context.Context, b []byte) error

Write sends one CDP WebSocket message.

type Stream

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

Stream carries complete NUL-delimited records over a bidirectional byte stream.

func NewStream

func NewStream(rw io.ReadWriteCloser) *Stream

NewStream wraps a transport whose Close interrupts blocked reads and writes.

func (*Stream) Close

func (s *Stream) Close() error

Close interrupts I/O and closes the underlying stream once.

func (*Stream) Read

func (s *Stream) Read(_ context.Context) ([]byte, error)

Read returns the next complete message; close the stream to interrupt it.

func (*Stream) Write

func (s *Stream) Write(ctx context.Context, b []byte) error

Write serializes complete records and closes the transport after an interrupted write.

type Transport

type Transport interface {
	Read(context.Context) ([]byte, error)
	Write(context.Context, []byte) error
	Close() error
}

Transport preserves message boundaries. Close must interrupt Read and Write.

Jump to

Keyboard shortcuts

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