cdp

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: MIT Imports: 13 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 is Daisybell's minimal Chrome DevTools Protocol client. It speaks flatten-mode sessions over a Transport (normally --remote-debugging-pipe) and implements github.com/chromedp/cdproto/cdp.Session so the generated cdproto commands and events can be used directly:

res, err := cdp.Call(ctx, sess, page.Navigate, page.NavigateParams{URL: u})

Index

Constants

View Source
const DefaultCallTimeout = 30 * time.Second

DefaultCallTimeout bounds a call whose context has no deadline.

Variables

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

ErrClosed is returned for calls on a closed connection or a detached session.

Functions

This section is empty.

Types

type Conn

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

Conn is a CDP connection multiplexing the browser session and any number of flatten-mode target sessions.

func NewConn

func NewConn(t Transport, log *slog.Logger) *Conn

NewConn starts reading from t. Close the Conn to release it.

func (*Conn) Attach

func (c *Conn) Attach(ctx context.Context, id target.ID) (*Session, error)

Attach attaches to a target in flatten mode and returns its session.

func (*Conn) Browser

func (c *Conn) Browser() *Session

Browser returns the browser-level session (no sessionId).

func (*Conn) Close

func (c *Conn) Close() error

Close closes the transport and fails every pending call.

func (*Conn) Done

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

Done is closed when the connection ends; Err then reports why.

func (*Conn) Err

func (c *Conn) Err() error

Err returns the reason the connection ended, or nil while it is open.

func (*Conn) Session

func (c *Conn) Session(id string) *Session

Session returns a handle for a flatten-mode session id obtained from Target.attachToTarget.

func (*Conn) Targets

func (c *Conn) Targets(ctx context.Context) ([]*target.Info, error)

Targets lists the browser's targets.

type Event

type Event struct {
	SessionID string
	Method    string
	Params    jsontext.Value
}

Event is a CDP event as received on the wire.

type RemoteError

type RemoteError struct {
	Method  string
	Code    int64  `json:"code"`
	Message string `json:"message"`
	Data    string `json:"data,omitempty"`
}

RemoteError is an error returned by the browser for a command.

func (*RemoteError) Error

func (e *RemoteError) Error() string

type Session

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

Session is a CDP session: the browser session (empty id) or a flatten-mode target session. It implements github.com/chromedp/cdproto/cdp.Session.

func (*Session) Call

func (s *Session) Call(ctx context.Context, method string, params, result any) error

Call sends the command and decodes the result into result (which may be nil).

func (*Session) Conn

func (s *Session) Conn() *Conn

Conn returns the underlying connection.

func (*Session) ID

func (s *Session) ID() string

ID is the flatten-mode session id ("" for the browser session).

func (*Session) Raw

func (s *Session) Raw(ctx context.Context, method string, params any) (jsontext.Value, error)

Raw sends the command and returns the undecoded result.

func (*Session) Subscribe

func (s *Session) Subscribe(method string) (<-chan jsontext.Value, func())

Subscribe buffers the session's events of method (or "*" for all) until cancel is called. The channel closes on cancel, on detach and when the connection ends.

func (*Session) SubscribeEvents

func (s *Session) SubscribeEvents(method string) (<-chan Event, func())

SubscribeEvents is like Subscribe but yields whole events, including the method name.

type Transport

type Transport interface {
	// ReadMessage blocks until a complete message arrives. It returns io.EOF when the browser
	// closed its end.
	ReadMessage() ([]byte, error)
	// WriteMessage sends one message. It is safe for concurrent use.
	WriteMessage(msg []byte) error
	// Close releases the transport; pending reads fail.
	Close() error
}

Transport moves whole CDP messages (one JSON object each) to and from the browser.

func NewPipeTransport

func NewPipeTransport(r io.Reader, w io.Writer, closers ...io.Closer) Transport

NewPipeTransport frames messages over r (browser → us) and w (us → browser). The closers are closed by Close, typically the two pipe ends.

Jump to

Keyboard shortcuts

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