Documentation
¶
Overview ¶
Package cdp speaks the Chrome DevTools Protocol to a browser's DevTools WebSocket endpoint: one JSON object per message, commands answered by id, events in between.
The endpoint is the one --remote-debugging-port opens, given a port number. The other transport Chrome has, --remote-debugging-pipe, would need no WebSocket, but a browser started with it -- or with port 0 -- declares itself automated to every page (navigator.webdriver is true), and a challenge page reads that first.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrHandshake = errors.New("websocket handshake failed") ErrProtocol = errors.New("websocket protocol error") ErrMessageTooLarge = errors.New("websocket message too large") )
var ErrClosed = errors.New("cdp connection closed")
Functions ¶
func Click ¶
Click moves the mouse to the point from somewhere below and to its left and presses it there, at the pace of a hand rather than in one event.
func IsTransient ¶
IsTransient reports whether the error is the browser declining a command for now -- a document being replaced has no nodes for a moment -- rather than the page or the connection being gone, which waiting does not mend.
Types ¶
type Caller ¶
type Caller interface {
Call(ctx context.Context, sessionId string, method string, params any, result any) error
}
Caller sends a command and decodes its result; *Conn is one, and a test's fake browser another.
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn is one connection to a browser. Commands may be sent from several goroutines; events are read and dropped, since nothing here waits on one.
func NewConn ¶
NewConn starts reading the browser's messages and returns the connection. Reading ends, and every pending and later command fails, when the transport does.
func (*Conn) Call ¶
func (c *Conn) Call(ctx context.Context, sessionId string, method string, params any, result any) error
Call sends a command and decodes its result into result, which may be nil. An empty session id addresses the browser itself; a page is addressed through the session Target.attachToTarget returned for it.
type ProtocolError ¶
ProtocolError is an error the browser answered a command with.
func (*ProtocolError) Error ¶
func (e *ProtocolError) Error() string
type Transport ¶
type Transport interface {
ReadMessage() ([]byte, error)
WriteMessage(data []byte) error
Close() error
}
Transport carries whole messages; *WebSocket is one.
type WebSocket ¶
type WebSocket struct {
// contains filtered or unexported fields
}
WebSocket is one client connection.
func DialWebSocket ¶
DialWebSocket opens a WebSocket to a ws:// URL.
func (*WebSocket) Close ¶
Close ends the connection without the closing handshake; the browser it is to is about to be closed anyway.
func (*WebSocket) ReadMessage ¶
ReadMessage returns the next text or binary message, answering pings on the way. A close from the server ends the connection with io.EOF.
func (*WebSocket) WriteMessage ¶
WriteMessage sends one text message.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package chrome starts a headed Chrome and connects to it over the DevTools protocol, the way a page behind a bot check needs it driven.
|
Package chrome starts a headed Chrome and connects to it over the DevTools protocol, the way a page behind a bot check needs it driven. |
|
Package turnstile passes Cloudflare's Turnstile the way a person does: when its widget asks whether the browser is human, it clicks the box.
|
Package turnstile passes Cloudflare's Turnstile the way a person does: when its widget asks whether the browser is human, it clicks the box. |