chrome

package
v1.0.0-rc8 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2019 License: BSD-2-Clause Imports: 14 Imported by: 0

Documentation

Overview

Package chrome aims to be a complete Chrome DevTools Protocol Viewer implementation.

This version implements the Tip-of-Tree API. See https://chromedevtools.github.io/devtools-protocol/tot/ for details.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Chrome

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

Chrome implements Chromium.

func New

func New(
	flags ChromiumFlags,
	binary string,
	workdir string,
	stdout string,
	stderr string,
) *Chrome

New returns a pointer to a Chromium instance.

func (*Chrome) Address

func (chrome *Chrome) Address() string

Address implements Chromium.

Default value is 'localhost'

func (*Chrome) Binary

func (chrome *Chrome) Binary() string

Binary implements Chromium.

Default value is '/usr/bin/google-chrome' for use with the mkenney/chromium-headless Docker image.

func (*Chrome) Close

func (chrome *Chrome) Close() error

Close implements Chromium.

func (*Chrome) DebuggingAddress

func (chrome *Chrome) DebuggingAddress() string

DebuggingAddress implements Chromium.

Default value is '0.0.0.0'.

func (*Chrome) DebuggingPort

func (chrome *Chrome) DebuggingPort() int

DebuggingPort implements Chromium.

func (*Chrome) Flags

func (chrome *Chrome) Flags() ChromiumFlags

Flags implements Chromium.

func (*Chrome) GetTab

func (chrome *Chrome) GetTab(tabID string) (Tabber, error)

GetTab implements Chromium.

func (*Chrome) Launch

func (chrome *Chrome) Launch() error

Launch implements Chromium.

This implementation makes it's best effort to set a few sane default values if they aren't included in the Flags definition:

addr = "localhost"
remote-debugging-address = "0.0.0.0"
remote-debugging-port = 9222
port = 9222
user-data-dir = os.TempDir() + chrome.Workdir()
chrome.workdir = "headless-chrome"
chrome.output = "/dev/stdout"

func (*Chrome) NewTab

func (chrome *Chrome) NewTab(uri string) (*Tab, error)

NewTab spawns a new Tab and returns a reference to it

func (*Chrome) Port

func (chrome *Chrome) Port() int

Port implements Chromium.

Default value is 9222

func (*Chrome) Query

func (chrome *Chrome) Query(
	path string,
	params url.Values,
	msg interface{},
) (interface{}, error)

Query implements Chromium.

func (*Chrome) RemoveTab

func (chrome *Chrome) RemoveTab(tab *Tab)

RemoveTab implements Chromium.

func (*Chrome) STDERR

func (chrome *Chrome) STDERR() string

STDERR implements Chromium.

func (*Chrome) STDOUT

func (chrome *Chrome) STDOUT() string

STDOUT implements Chromium.

func (*Chrome) Tabs

func (chrome *Chrome) Tabs() []*Tab

Tabs implements Chromium.

func (*Chrome) Version

func (chrome *Chrome) Version() (*Version, error)

Version implements Chromium.

func (*Chrome) Workdir

func (chrome *Chrome) Workdir() string

Workdir implements Chromium.

Default value is /tmp/headless-chrome

type Chromium

type Chromium interface {
	// Address returns the domain to use for accessing Chrome sockets (e.g.
	// 'localhost'). Should return a sane default value such as 'localhost'.
	Address() string

	// Binary returns the path to the Chromium binary. Should return a sane
	// default value such as '/usr/bin/google-chrome'.
	Binary() string

	// Close ends the Chromium process and cleans up.
	Close() error

	// GetTab returns an open Tabber instance, or an error if the requested tab
	// does not exist.
	GetTab(tabID string) (tab Tabber, err error)

	// RemoveTab removes tab reference from chrome tabs list.
	RemoveTab(tab *Tab)

	// DebuggingAddress returns the address that the remote debugging protocol
	// is available on. Should return a sane default value such as '0.0.0.0'.
	DebuggingAddress() string

	// DebuggingPort is the port number that the remote debugging protocol is
	// available on. Should return a sane default value such as 9222.
	DebuggingPort() int

	// Args returns a ChromiumFlags interface used to define and manage CLI
	// arguments to the Chromium binary. Only used when starting the chromium
	// system process.
	Flags() ChromiumFlags

	// Launch launches the Chromium process and returns the connected Chromium
	// struct.
	Launch() error

	// NewTab spawns a new tab and returns a reference to it.
	NewTab(url string) (*Tab, error)

	// Port returns the port number the developer tools endpoints will listen
	// on. Should return a sane default value such as 9222.
	Port() int

	// Query queries the developer tools endpoints and returns JSON data in the
	// provided struct.
	Query(path string, params url.Values, msg interface{}) (interface{}, error)

	// STDERR returns a string defining the location to write STDERR output.
	STDERR() string

	// STDOUT returns a string defining the location to write STDOUT output.
	STDOUT() string

	// Tabs returns the list of the currently open tabs.
	Tabs() []*Tab

	// Version returns Chromium version data.
	Version() (*Version, error)

	// Workdir returns the path of the Chromium working directory. Should return
	// a sane default value such as '/tmp/headless-chrome'.
	Workdir() string
}

Chromium defines an interface for interacting with Chromium based web browsers

type ChromiumFlags

type ChromiumFlags interface {

	// Get returns the specified flag values
	Get(flag string) (interface{}, error)

	// Has checks to see if an flag is present.
	Has(flag string) bool

	// List returns an array of each flag for use in os.StartProcess
	List() []string

	// Set sets a flag's values.
	Set(flag string, values interface{}) error

	// String implments Stringer. It returns the set parameters formatted to be
	// passed to the command line.
	String() string
}

ChromiumFlags provides an interface for managing CLI arguments to the Chromium binary.

type Flags

type Flags map[string]interface{}

Flags contains CLI arguments to the Chromium executable.

func (Flags) Get

func (flags Flags) Get(arg string) (interface{}, error)

Get implements ChromiumFlags

func (Flags) Has

func (flags Flags) Has(arg string) bool

Has implements ChromiumFlags

func (Flags) List

func (flags Flags) List() []string

List implements ChromiumFlags

func (Flags) Set

func (flags Flags) Set(arg string, value interface{}) (err error)

Set implements ChromiumFlags

func (Flags) String

func (flags Flags) String() string

String implements ChromiumFlags

type Socketer

type Socketer interface {
	// AddEventHandler adds an event handler to the stack of listeners for an
	// event.
	AddEventHandler(handler socket.EventHandler)

	// RemoveEventHandler removes a handler from the stack of listeners for an
	// event.
	RemoveEventHandler(handler socket.EventHandler)

	// SendCommand delivers a command payload to the websocket connection.
	SendCommand(command socket.Commander) *socket.Payload
}

Socketer defins a simple socket interface for the tab struct to implement

type Tab

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

Tab is a struct representing an individual Chrome tab

func (*Tab) Accessibility

func (tab *Tab) Accessibility() *socket.AccessibilityProtocol

Accessibility implements socket.Protocoller

func (*Tab) AddEventHandler

func (tab *Tab) AddEventHandler(handler socket.EventHandler)

AddEventHandler implements Socketer

func (*Tab) Animation

func (tab *Tab) Animation() *socket.AnimationProtocol

Animation implements socket.Protocoller

func (*Tab) ApplicationCache

func (tab *Tab) ApplicationCache() *socket.ApplicationCacheProtocol

ApplicationCache implements socket.Protocoller

func (*Tab) Audits

func (tab *Tab) Audits() *socket.AuditsProtocol

Audits implements socket.Protocoller

func (*Tab) Browser

func (tab *Tab) Browser() *socket.BrowserProtocol

Browser implements socket.Protocoller

func (*Tab) CSS

func (tab *Tab) CSS() *socket.CSSProtocol

CSS implements socket.Protocoller

func (*Tab) CacheStorage

func (tab *Tab) CacheStorage() *socket.CacheStorageProtocol

CacheStorage implements socket.Protocoller

func (*Tab) Chromium

func (tab *Tab) Chromium() Chromium

Chromium implements Tabber.

func (*Tab) Close

func (tab *Tab) Close() (interface{}, error)

Close implements Tabber.

func (*Tab) Console

func (tab *Tab) Console() *socket.ConsoleProtocol

Console implements socket.Protocoller

func (*Tab) DOM

func (tab *Tab) DOM() *socket.DOMProtocol

DOM implements socket.Protocoller

func (*Tab) DOMDebugger

func (tab *Tab) DOMDebugger() *socket.DOMDebuggerProtocol

DOMDebugger implements socket.Protocoller

func (*Tab) DOMSnapshot

func (tab *Tab) DOMSnapshot() *socket.DOMSnapshotProtocol

DOMSnapshot implements socket.Protocoller

func (*Tab) DOMStorage

func (tab *Tab) DOMStorage() *socket.DOMStorageProtocol

DOMStorage implements socket.Protocoller

func (*Tab) Data

func (tab *Tab) Data() *TabData

Data implements Tabber.

func (*Tab) Database

func (tab *Tab) Database() *socket.DatabaseProtocol

Database implements socket.Protocoller

func (*Tab) Debugger

func (tab *Tab) Debugger() *socket.DebuggerProtocol

Debugger implements socket.Protocoller

func (*Tab) DeviceOrientation

func (tab *Tab) DeviceOrientation() *socket.DeviceOrientationProtocol

DeviceOrientation implements socket.Protocoller

func (*Tab) Emulation

func (tab *Tab) Emulation() *socket.EmulationProtocol

Emulation implements socket.Protocoller

func (*Tab) HeadlessExperimental

func (tab *Tab) HeadlessExperimental() *socket.HeadlessExperimentalProtocol

HeadlessExperimental implements socket.Protocoller

func (*Tab) HeapProfiler

func (tab *Tab) HeapProfiler() *socket.HeapProfilerProtocol

HeapProfiler implements socket.Protocoller

func (*Tab) IO

func (tab *Tab) IO() *socket.IOProtocol

IO implements socket.Protocoller

func (*Tab) IndexedDB

func (tab *Tab) IndexedDB() *socket.IndexedDBProtocol

IndexedDB implements socket.Protocoller

func (*Tab) Input

func (tab *Tab) Input() *socket.InputProtocol

Input implements socket.Protocoller

func (*Tab) LayerTree

func (tab *Tab) LayerTree() *socket.LayerTreeProtocol

LayerTree implements socket.Protocoller

func (*Tab) Log

func (tab *Tab) Log() *socket.LogProtocol

Log implements socket.Protocoller

func (*Tab) Memory

func (tab *Tab) Memory() *socket.MemoryProtocol

Memory implements socket.Protocoller

func (*Tab) Network

func (tab *Tab) Network() *socket.NetworkProtocol

Network implements socket.Protocoller

func (*Tab) Overlay

func (tab *Tab) Overlay() *socket.OverlayProtocol

Overlay implements socket.Protocoller

func (*Tab) Page

func (tab *Tab) Page() *socket.PageProtocol

Page implements socket.Protocoller

func (*Tab) Performance

func (tab *Tab) Performance() *socket.PerformanceProtocol

Performance implements socket.Protocoller

func (*Tab) Profiler

func (tab *Tab) Profiler() *socket.ProfilerProtocol

Profiler implements socket.Protocoller

func (*Tab) Protocol

func (tab *Tab) Protocol() socket.Protocoller

Protocol implements Tabber.

func (*Tab) RemoveEventHandler

func (tab *Tab) RemoveEventHandler(handler socket.EventHandler)

RemoveEventHandler implements Socketer

func (*Tab) Runtime

func (tab *Tab) Runtime() *socket.RuntimeProtocol

Runtime implements socket.Protocoller

func (*Tab) Schema

func (tab *Tab) Schema() *socket.SchemaProtocol

Schema implements socket.Protocoller

func (*Tab) Security

func (tab *Tab) Security() *socket.SecurityProtocol

Security implements socket.Protocoller

func (*Tab) SendCommand

func (tab *Tab) SendCommand(command socket.Commander) chan *socket.Response

SendCommand implements Socketer

func (*Tab) ServiceWorker

func (tab *Tab) ServiceWorker() *socket.ServiceWorkerProtocol

ServiceWorker implements socket.Protocoller

func (*Tab) Socket

func (tab *Tab) Socket() socket.Socketer

Socket implements Tabber.

func (*Tab) Storage

func (tab *Tab) Storage() *socket.StorageProtocol

Storage implements socket.Protocoller

func (*Tab) SystemInfo

func (tab *Tab) SystemInfo() *socket.SystemInfoProtocol

SystemInfo implements socket.Protocoller

func (*Tab) Target

func (tab *Tab) Target() *socket.TargetProtocol

Target implements socket.Protocoller

func (*Tab) Tethering

func (tab *Tab) Tethering() *socket.TetheringProtocol

Tethering implements socket.Protocoller

func (*Tab) Tracing

func (tab *Tab) Tracing() *socket.TracingProtocol

Tracing implements socket.Protocoller

func (*Tab) URL

func (tab *Tab) URL() *url.URL

URL implements Tabber.

type TabData

type TabData struct {
	Description          string `json:"description"`
	DevtoolsFrontendURL  string `json:"devtoolsFrontendURL"`
	ID                   string `json:"id"`
	Title                string `json:"title"`
	Type                 string `json:"type"`
	URL                  string `json:"url"`
	WebSocketDebuggerURL string `json:"webSocketDebuggerURL"`
}

TabData holds metadata about a browser tab

type Tabber

type Tabber interface {
	// Browser returns the Chromium instance this tab is in
	Chromium() Chromium

	// Close closes this chromium tab
	Close() (interface{}, error)

	// Data returns the tab metadata
	Data() *TabData

	// Protocol returns the socket.Protocoller interface for this tab
	Protocol() socket.Protocoller

	// Socket returns the socket.Socketer interface for this tab
	Socket() socket.Socketer

	// URL returns the URL of the websocket connection
	URL() *url.URL
}

Tabber provides an interface for managing a Chromium tab

type Version

type Version struct {
	Browser              string `json:"browser"`
	ProtocolVersion      string `json:"protocol-version"`
	UserAgent            string `json:"user-agent"`
	V8Version            string `json:"v8-version"`
	WebKitVersion        string `json:"webkit-version"`
	WebSocketDebuggerURL string `json:"webSocketDebuggerUrl"`
}

Version is a struct representing the Chromium version information.

Directories

Path Synopsis
Package accessibility provides type definitions for use with the Chrome Accessibility protocol
Package accessibility provides type definitions for use with the Chrome Accessibility protocol
Package animation provides type definitions for use with the Chrome Animation protocol
Package animation provides type definitions for use with the Chrome Animation protocol
application
cache
Package cache provides type definitions for use with the Chrome ApplicationCache protocol
Package cache provides type definitions for use with the Chrome ApplicationCache protocol
Package audits provides type definitions for use with the Chrome Audits protocol
Package audits provides type definitions for use with the Chrome Audits protocol
Package browser provides type definitions for use with the Chrome Browser protocol
Package browser provides type definitions for use with the Chrome Browser protocol
cache
storage
Package storage provides type definitions for use with the Chrome CacheStorage protocol
Package storage provides type definitions for use with the Chrome CacheStorage protocol
Package console provides type definitions for use with the Chrome Console protocol
Package console provides type definitions for use with the Chrome Console protocol
Package css provides type definitions for use with the Chrome CSS protocol
Package css provides type definitions for use with the Chrome CSS protocol
Package database provides type definitions for use with the Chrome Database protocol
Package database provides type definitions for use with the Chrome Database protocol
Package debugger provides type definitions for use with the Chrome Debugger protocol
Package debugger provides type definitions for use with the Chrome Debugger protocol
device
orientation
Package orientation provides type definitions for use with the Chrome DeviceOrientation protocol
Package orientation provides type definitions for use with the Chrome DeviceOrientation protocol
dom
Package dom provides type definitions for use with the Chrome DOM protocol
Package dom provides type definitions for use with the Chrome DOM protocol
debugger
Package debugger provides type definitions for use with the Chrome DOMDebugger protocol
Package debugger provides type definitions for use with the Chrome DOMDebugger protocol
snapshot
Package snapshot provides type definitions for use with the Chrome DOMSnapshot protocol
Package snapshot provides type definitions for use with the Chrome DOMSnapshot protocol
storage
Package storage provides type definitions for use with the Chrome DOMStorage protocol
Package storage provides type definitions for use with the Chrome DOMStorage protocol
Package emulation provides type definitions for use with the Chrome Emulation protocol
Package emulation provides type definitions for use with the Chrome Emulation protocol
headless
experimental
Package experimental provides type definitions for use with the Chrome HeadlessExperimental protocol
Package experimental provides type definitions for use with the Chrome HeadlessExperimental protocol
heap
profiler
Package profiler provides type definitions for use with the Chrome HeapProfiler protocol
Package profiler provides type definitions for use with the Chrome HeapProfiler protocol
indexed
db
Package db provides type definitions for use with the Chrome IndexedDB protocol
Package db provides type definitions for use with the Chrome IndexedDB protocol
Package input provides type definitions for use with the Chrome Input protocol
Package input provides type definitions for use with the Chrome Input protocol
Package io provides type definitions for use with the Chrome IO protocol
Package io provides type definitions for use with the Chrome IO protocol
layer
tree
Package tree provides type definitions for use with the Chrome LayerTree protocol
Package tree provides type definitions for use with the Chrome LayerTree protocol
Package log provides type definitions for use with the Chrome Log protocol
Package log provides type definitions for use with the Chrome Log protocol
Package memory provides type definitions for use with the Chrome Memory protocol
Package memory provides type definitions for use with the Chrome Memory protocol
Package network provides type definitions for use with the Chrome Network protocol
Package network provides type definitions for use with the Chrome Network protocol
Package overlay provides type definitions for use with the Chrome Overlay protocol
Package overlay provides type definitions for use with the Chrome Overlay protocol
Package page provides type definitions for use with the Chrome Page protocol
Package page provides type definitions for use with the Chrome Page protocol
Package performance provides type definitions for use with the Chrome Performance protocol
Package performance provides type definitions for use with the Chrome Performance protocol
Package profiler provides type definitions for use with the Chrome Profiler protocol
Package profiler provides type definitions for use with the Chrome Profiler protocol
Package runtime provides type definitions for use with the Chrome Runtime protocol
Package runtime provides type definitions for use with the Chrome Runtime protocol
Package schema provides type definitions for use with the Chrome Schema protocol
Package schema provides type definitions for use with the Chrome Schema protocol
Package security provides type definitions for use with the Chrome Security protocol
Package security provides type definitions for use with the Chrome Security protocol
service
worker
Package worker provides type definitions for use with the Chrome ServiceWorker protocol
Package worker provides type definitions for use with the Chrome ServiceWorker protocol
Package socket allows for tools to instrument, inspect, debug and profile Chromium, Chrome and other Blink-based browsers.
Package socket allows for tools to instrument, inspect, debug and profile Chromium, Chrome and other Blink-based browsers.
Package storage provides type definitions for use with the Chrome Storage protocol
Package storage provides type definitions for use with the Chrome Storage protocol
system
info
Package info provides type definitions for use with the Chrome SystemInfo protocol
Package info provides type definitions for use with the Chrome SystemInfo protocol
Package target provides type definitions for use with the Chrome Target protocol
Package target provides type definitions for use with the Chrome Target protocol
Package tethering provides type definitions for use with the Chrome Tethering protocol
Package tethering provides type definitions for use with the Chrome Tethering protocol
Package tracing provides type definitions for use with the Chrome Tracing protocol
Package tracing provides type definitions for use with the Chrome Tracing protocol

Jump to

Keyboard shortcuts

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