Documentation ¶
Index ¶
- type Client
- func (cdp *Client) Call(ctx context.Context, sessionID, method string, params interface{}) ([]byte, error)
- func (cdp *Client) Connect() *Client
- func (cdp *Client) ConnectE() error
- func (cdp *Client) Context(ctx context.Context, cancel func()) *Client
- func (cdp *Client) Debug(enable bool) *Client
- func (cdp *Client) DebugLog(fn func(interface{})) *Client
- func (cdp *Client) Event() <-chan *Event
- func (cdp *Client) Header(header http.Header) *Client
- func (cdp *Client) Websocket(ws Websocketable) *Client
- type DefaultWsClient
- type DefaultWsConn
- type Error
- type Event
- type Request
- type Websocketable
- type WebsocketableConn
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a devtools protocol connection instance.
Example ¶
package main import ( "context" "github.com/go-rod/rod/lib/cdp" "github.com/go-rod/rod/lib/launcher" "github.com/ysmood/kit" ) func main() { // launch a browser url := launcher.New().Headless(false).Launch() // create a controller client := cdp.New(url).Connect() // Such as call this endpoint on the api doc: // https://chromedevtools.github.io/devtools-protocol/tot/Page#method-navigate // This will create a new tab and navigate to the test.com res, err := client.Call(context.Background(), "", "Target.createTarget", map[string]string{ "url": "https://google.com", }) kit.E(err) kit.Log(kit.JSON(res).Get("targetId").String()) kit.Pause() // Skip
Output:
func New ¶
New creates a cdp connection, all messages from Client.Event must be received or they will block the client.
func (*Client) Call ¶
func (cdp *Client) Call(ctx context.Context, sessionID, method string, params interface{}) ([]byte, error)
Call a method and get its response, if ctx is nil context.Background() will be used
func (*Client) Event ¶
Event returns a channel that will emit browser devtools protocol events. Must be consumed or will block producer.
func (*Client) Websocket ¶
func (cdp *Client) Websocket(ws Websocketable) *Client
Websocket set the websocket lib to use
type DefaultWsClient ¶
type DefaultWsClient struct {
WriteBufferSize int
}
DefaultWsClient is the default websocket client
func (DefaultWsClient) Connect ¶
func (c DefaultWsClient) Connect(ctx context.Context, url string, header http.Header) (WebsocketableConn, error)
Connect interface
type DefaultWsConn ¶
type DefaultWsConn struct {
// contains filtered or unexported fields
}
DefaultWsConn is the default websocket connection type
type Error ¶
type Error struct { Code int64 `json:"code"` Message string `json:"message"` Data string `json:"data"` }
Error of the Response
type Event ¶
type Event struct { SessionID string `json:"sessionId,omitempty"` Method string `json:"method"` Params json.RawMessage `json:"params,omitempty"` }
Event from browser
type Request ¶
type Request struct { ID uint64 `json:"id"` SessionID string `json:"sessionId,omitempty"` Method string `json:"method"` Params interface{} `json:"params,omitempty"` }
Request to send to browser
type Websocketable ¶
type Websocketable interface { // Connect to server Connect(ctx context.Context, url string, header http.Header) (WebsocketableConn, error) }
Websocketable enables you to choose the websocket lib you want to use. By default cdp use github.com/gorilla/websocket