devtool

package
v0.16.3 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2018 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package devtool provides methods for interacting with a DevTools endpoint.

To activate the DevTools endpoint, a browser (or other debug target) should be started with debugging enabled:

chromium --remote-debugging-port=9222
./<path>/EdgeDiagnosticsAdapter.exe --port 9223
node --inspect=9224

Create a new DevTools instance that interacts with the given URL:

devt := devtool.New("http://127.0.0.1:9222")

Get the active page or create a new one:

devt := devtool.New("http://127.0.0.1:9222")
page, err := devt.Get(context.Background(), devtool.Page)
if err != nil {
	page, err = devt.Create(context.Background())
	if err != nil {
		// Handle error.
	}
}
// ...

Set request timeouts via contexts:

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

devt := devtool.New("http://127.0.0.1:9222")
list, err := devt.List(ctx)
if err != nil {
	// Handle error.
}
// ...

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DevTools

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

DevTools represents a devtools endpoint for managing and querying information about targets.

func New

func New(url string, opts ...DevToolsOption) *DevTools

New returns a DevTools instance that uses URL.

func (*DevTools) Activate

func (d *DevTools) Activate(ctx context.Context, t *Target) error

Activate brings focus to the Target.

func (*DevTools) Close

func (d *DevTools) Close(ctx context.Context, t *Target) error

Close the Target.

func (*DevTools) Create

func (d *DevTools) Create(ctx context.Context) (*Target, error)

Create a new Target, usually a page with about:blank as URL.

func (*DevTools) CreateURL

func (d *DevTools) CreateURL(ctx context.Context, openURL string) (*Target, error)

CreateURL is like Create but opens the provided URL. The URL must be valid and begin with "http://" or "https://".

func (*DevTools) Get

func (d *DevTools) Get(ctx context.Context, typ Type) (*Target, error)

Get the first Target that matches Type.

func (*DevTools) List

func (d *DevTools) List(ctx context.Context) ([]*Target, error)

List returns a list with all devtools Targets.

func (*DevTools) Version

func (d *DevTools) Version(ctx context.Context) (*Version, error)

Version returns the version information for the DevTools endpoint.

type DevToolsOption

type DevToolsOption func(*DevTools)

DevToolsOption represents a function that sets a DevTools option.

func WithClient

func WithClient(client *http.Client) DevToolsOption

WithClient returns a DevToolsOption that sets the http Client used for HTTP GET requests.

type Target

type Target struct {
	Description          string `json:"description"`
	DevToolsFrontendURL  string `json:"devtoolsFrontendUrl"`
	ID                   string `json:"id"`
	Title                string `json:"title"`
	Type                 Type   `json:"type"`
	URL                  string `json:"url"`
	WebSocketDebuggerURL string `json:"webSocketDebuggerUrl"`
}

Target represents a devtools target, e.g. a browser tab.

type Type

type Type string

Type represents the type of Target.

const (
	BackgroundPage Type = "background_page"
	Node           Type = "node"
	Other          Type = "other"
	Page           Type = "page"
	ServiceWorker  Type = "service_worker"
)

Type enums.

type Version

type Version struct {
	// Present in Chrome, Edge, Node, etc.
	Browser  string `json:"Browser"`
	Protocol string `json:"Protocol-Version"`

	// Present in Chrome, Edge.
	UserAgent string `json:"User-Agent"`
	V8        string `json:"V8-Version"`
	WebKit    string `json:"WebKit-Version"`

	// Present on Android.
	AndroidPackage string `json:"Android-Package"`

	// Present in Chrome >= 62. Generic browser websocket URL.
	WebSocketDebuggerURL string `json:"websocketDebuggerUrl"`
}

Version contains the version information for the DevTools endpoint.

Jump to

Keyboard shortcuts

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