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
- Variables
- type Conn
- func (c *Conn) Attach(ctx context.Context, id target.ID) (*Session, error)
- func (c *Conn) Browser() *Session
- func (c *Conn) Close() error
- func (c *Conn) Done() <-chan struct{}
- func (c *Conn) Err() error
- func (c *Conn) Session(id string) *Session
- func (c *Conn) Targets(ctx context.Context) ([]*target.Info, error)
- type Event
- type RemoteError
- type Session
- func (s *Session) Call(ctx context.Context, method string, params, result any) error
- func (s *Session) Conn() *Conn
- func (s *Session) ID() string
- func (s *Session) Raw(ctx context.Context, method string, params any) (jsontext.Value, error)
- func (s *Session) Subscribe(method string) (<-chan jsontext.Value, func())
- func (s *Session) SubscribeEvents(method string) (<-chan Event, func())
- type Transport
Constants ¶
const DefaultCallTimeout = 30 * time.Second
DefaultCallTimeout bounds a call whose context has no deadline.
Variables ¶
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 (*Conn) Done ¶
func (c *Conn) Done() <-chan struct{}
Done is closed when the connection ends; Err then reports why.
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 ¶
Call sends the command and decodes the result into result (which may be nil).
func (*Session) Subscribe ¶
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 ¶
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.