client

package
v0.0.0-...-f2f8d4e Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2020 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package client provides the low level Chrome DevTools Protocol client.

Index

Constants

View Source
const (
	// DefaultEndpoint is the default endpoint to connect to.
	DefaultEndpoint = "http://localhost:9222/json"

	// DefaultWatchInterval is the default check duration.
	DefaultWatchInterval = 100 * time.Millisecond

	// DefaultWatchTimeout is the default watch timeout.
	DefaultWatchTimeout = 5 * time.Second
)

Variables

View Source
var (
	// DefaultReadBufferSize is the default maximum read buffer size.
	DefaultReadBufferSize = 25 * 1024 * 1024

	// DefaultWriteBufferSize is the default maximum write buffer size.
	DefaultWriteBufferSize = 10 * 1024 * 1024
)

Functions

This section is empty.

Types

type Chrome

type Chrome struct {
	Description  string     `json:"description,omitempty"`
	DevtoolsURL  string     `json:"devtoolsFrontendUrl,omitempty"`
	ID           string     `json:"id,omitempty"`
	Title        string     `json:"title,omitempty"`
	Type         TargetType `json:"type,omitempty"`
	URL          string     `json:"url,omitempty"`
	WebsocketURL string     `json:"webSocketDebuggerUrl,omitempty"`
	FaviconURL   string     `json:"faviconURL,omitempty"`
}

Chrome holds connection information for a Chrome target.

func (*Chrome) GetDevtoolsURL

func (c *Chrome) GetDevtoolsURL() string

GetDevtoolsURL returns the devtools frontend target URL, satisfying the domains.Target interface.

func (*Chrome) GetID

func (c *Chrome) GetID() string

GetID returns the target ID.

func (*Chrome) GetType

func (c *Chrome) GetType() TargetType

GetType returns the target type.

func (*Chrome) GetWebsocketURL

func (c *Chrome) GetWebsocketURL() string

GetWebsocketURL provides the websocket URL for the target, satisfying the domains.Target interface.

func (Chrome) MarshalEasyJSON

func (v Chrome) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Chrome) MarshalJSON

func (v Chrome) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (Chrome) String

func (c Chrome) String() string

String satisfies the stringer interface.

func (*Chrome) UnmarshalEasyJSON

func (v *Chrome) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Chrome) UnmarshalJSON

func (v *Chrome) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type Client

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

Client is a Chrome DevTools Protocol client.

func New

func New(opts ...Option) *Client

New creates a new Chrome DevTools Protocol client.

func (*Client) ActivateTarget

func (c *Client) ActivateTarget(ctxt context.Context, t Target) error

ActivateTarget activates a target.

func (*Client) CloseTarget

func (c *Client) CloseTarget(ctxt context.Context, t Target) error

CloseTarget activates a target.

func (*Client) ListPageTargets

func (c *Client) ListPageTargets(ctxt context.Context) ([]Target, error)

ListPageTargets lists the available Page targets.

func (*Client) ListTargets

func (c *Client) ListTargets(ctxt context.Context) ([]Target, error)

ListTargets returns a list of all targets.

func (*Client) ListTargetsWithType

func (c *Client) ListTargetsWithType(ctxt context.Context, typ TargetType) ([]Target, error)

ListTargetsWithType returns a list of Targets with the specified target type.

func (*Client) NewPageTarget

func (c *Client) NewPageTarget(ctxt context.Context) (Target, error)

NewPageTarget creates a new page target.

func (*Client) NewPageTargetWithURL

func (c *Client) NewPageTargetWithURL(ctxt context.Context, urlstr string) (Target, error)

NewPageTargetWithURL creates a new page target with the specified url.

func (*Client) VersionInfo

func (c *Client) VersionInfo(ctxt context.Context) (map[string]string, error)

VersionInfo returns information about the remote debugging protocol.

func (*Client) WatchPageTargets

func (c *Client) WatchPageTargets(ctxt context.Context) <-chan Target

WatchPageTargets watches for new page targets.

type Conn

type Conn struct {
	*websocket.Conn
}

Conn wraps a gorilla/websocket.Conn connection.

func (*Conn) Read

func (c *Conn) Read() ([]byte, error)

Read reads the next websocket message.

func (*Conn) Write

func (c *Conn) Write(buf []byte) error

Write writes a websocket message.

type DialOption

type DialOption func(*websocket.Dialer)

DialOption is a dial option.

type Error

type Error string

Error is a client error.

const (
	// ErrUnsupportedProtocolType is the unsupported protocol type error.
	ErrUnsupportedProtocolType Error = "unsupported protocol type"

	// ErrUnsupportedProtocolVersion is the unsupported protocol version error.
	ErrUnsupportedProtocolVersion Error = "unsupported protocol version"
)

func (Error) Error

func (err Error) Error() string

Error satisfies the error interface.

type Option

type Option func(*Client)

Option is a Chrome DevTools Protocol client option.

func URL

func URL(urlstr string) Option

URL is a client option to specify the remote Chrome DevTools Protocol instance to connect to.

func WatchInterval

func WatchInterval(check time.Duration) Option

WatchInterval is a client option that specifies the check interval duration.

func WatchTimeout

func WatchTimeout(timeout time.Duration) Option

WatchTimeout is a client option that specifies the watch timeout duration.

type Target

type Target interface {
	String() string
	GetID() string
	GetType() TargetType
	GetDevtoolsURL() string
	GetWebsocketURL() string
}

Target is the common interface for a Chrome DevTools Protocol target.

type TargetType

type TargetType string

TargetType are the types of targets available in Chrome.

const (
	App            TargetType = "app"
	BackgroundPage TargetType = "background_page"
	Browser        TargetType = "browser"
	External       TargetType = "external"
	Iframe         TargetType = "iframe"
	Other          TargetType = "other"
	Page           TargetType = "page"
	ServiceWorker  TargetType = "service_worker"
	SharedWorker   TargetType = "shared_worker"
	Webview        TargetType = "webview"
	Worker         TargetType = "worker"
)

TargetType values.

func (TargetType) MarshalEasyJSON

func (tt TargetType) MarshalEasyJSON(out *jwriter.Writer)

MarshalEasyJSON satisfies easyjson.Marshaler.

func (TargetType) MarshalJSON

func (tt TargetType) MarshalJSON() ([]byte, error)

MarshalJSON satisfies json.Marshaler.

func (TargetType) String

func (tt TargetType) String() string

String satisfies stringer.

func (*TargetType) UnmarshalEasyJSON

func (tt *TargetType) UnmarshalEasyJSON(in *jlexer.Lexer)

UnmarshalEasyJSON satisfies easyjson.Unmarshaler.

func (*TargetType) UnmarshalJSON

func (tt *TargetType) UnmarshalJSON(buf []byte) error

UnmarshalJSON satisfies json.Unmarshaler.

type Transport

type Transport interface {
	Read() ([]byte, error)
	Write([]byte) error
	io.Closer
}

Transport is the common interface to send/receive messages to a target.

func Dial

func Dial(urlstr string, opts ...DialOption) (Transport, error)

Dial dials the specified target's websocket URL.

Note: uses gorilla/websocket.

Jump to

Keyboard shortcuts

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