Documentation ¶
Index ¶
- Variables
- func WithChromeCmdOutput(output io.Writer) func(*Gcd)
- func WithContext(ctx context.Context) func(*Gcd)
- func WithDebugPortTimeout(timeout time.Duration) func(*Gcd)
- func WithDeleteProfileOnExit() func(*Gcd)
- func WithEnvironmentVars(vars []string) func(*Gcd)
- func WithEventDebugging() func(*Gcd)
- func WithEventQueueSize(queueSize int) func(*Gcd)
- func WithFlags(flags []string) func(*Gcd)
- func WithInternalDebugMessages() func(*Gcd)
- func WithLogger(l Log) func(*Gcd)
- func WithMessageObserver(observer observer.MessageObserver) func(*Gcd)
- func WithOnChromeExitHandler(handler OnChromeExitHandler) func(*Gcd)
- func WithTerminationHandler(handler TerminatedHandler) func(*Gcd)
- type ChromeTarget
- func (c *ChromeTarget) GetApiTimeout() time.Duration
- func (c *ChromeTarget) GetDoneCh() chan struct{}
- func (c *ChromeTarget) GetId() int64
- func (c *ChromeTarget) GetSendCh() chan *gcdmessage.Message
- func (c *ChromeTarget) Init()
- func (c *ChromeTarget) SendCustomReturn(ctx context.Context, paramRequest *gcdmessage.ParamRequest) (*gcdmessage.Message, error)
- func (c *ChromeTarget) SendDefaultRequest(ctx context.Context, paramRequest *gcdmessage.ParamRequest) (*gcdmessage.ChromeResponse, error)
- func (c *ChromeTarget) SetApiTimeout(timeout time.Duration)
- func (c *ChromeTarget) Subscribe(method string, callback func(*ChromeTarget, []byte))
- func (c *ChromeTarget) Unsubscribe(method string)
- type DebugLogger
- type Dialer
- type ErrBadHandshake
- type Gcd
- func (c *Gcd) ActivateTab(target *ChromeTarget) error
- func (c *Gcd) CloseTab(target *ChromeTarget) error
- func (c *Gcd) ConnectToInstance(host string, port string) error
- func (c *Gcd) ExitProcess() error
- func (c *Gcd) GetNewTargets(knownIds map[string]struct{}) ([]*ChromeTarget, error)
- func (c *Gcd) GetRevision() string
- func (c *Gcd) GetTargets() ([]*ChromeTarget, error)
- func (c *Gcd) Host() string
- func (c *Gcd) NewTab() (*ChromeTarget, error)
- func (c *Gcd) PID() int
- func (c *Gcd) Port() string
- func (c *Gcd) StartProcess(exePath, userDir, port string) error
- func (c *Gcd) StartProcessCustom(cmd *exec.Cmd, userDir, port string) error
- type GcdBodyReadErr
- type GcdDecodingErr
- type Log
- type LogDiscarder
- type OnChromeExitHandler
- type TargetInfo
- type TerminatedHandler
- type WebSocket
Constants ¶
This section is empty.
Variables ¶
var (
ErrNoTabAvailable = errors.New("no available tab found")
)
var GCDVERSION = "v2.3.1"
Functions ¶
func WithChromeCmdOutput ¶ added in v2.2.3
WithChromeCmdOutput will send the STDOUT and STDERR output of the chrome process to the provided stream
func WithContext ¶ added in v2.1.1
func WithDebugPortTimeout ¶ added in v2.1.1
WithDebugPortTimeout for how long we should wait for debug port to become available.
func WithDeleteProfileOnExit ¶ added in v2.1.1
func WithDeleteProfileOnExit() func(*Gcd)
func WithEnvironmentVars ¶ added in v2.1.1
WithEnvironmentVars for the chrome process, useful for Xvfb etc.
func WithEventDebugging ¶ added in v2.1.1
func WithEventDebugging() func(*Gcd)
func WithEventQueueSize ¶ added in v2.2.0
WithEventQueueSize number of DevTool events to allow to queue up
func WithFlags ¶ added in v2.1.1
WithFlags allows caller to add additional startup flags to the chrome process
func WithInternalDebugMessages ¶ added in v2.1.1
func WithInternalDebugMessages() func(*Gcd)
func WithLogger ¶ added in v2.1.1
func WithMessageObserver ¶ added in v2.1.2
func WithMessageObserver(observer observer.MessageObserver) func(*Gcd)
func WithOnChromeExitHandler ¶ added in v2.1.4
func WithOnChromeExitHandler(handler OnChromeExitHandler) func(*Gcd)
WithOnChromeExitHandler Pass a handler to be notified when the chrome process exits.
func WithTerminationHandler ¶ added in v2.1.1
func WithTerminationHandler(handler TerminatedHandler) func(*Gcd)
WithTerminationHandler Pass a handler to be notified when the chrome process exits.
Types ¶
type ChromeTarget ¶
type ChromeTarget struct { // Chrome Debugger Domains Accessibility *gcdapi.Accessibility Animation *gcdapi.Animation Audits *gcdapi.Audits BackgroundService *gcdapi.BackgroundService Browser *gcdapi.Browser CacheStorage *gcdapi.CacheStorage Cast *gcdapi.Cast Console *gcdapi.Console // console API CSS *gcdapi.CSS // CSS API Database *gcdapi.Database // Database API Debugger *gcdapi.Debugger // JS Debugger API DeviceOrientation *gcdapi.DeviceOrientation // Device Orientation API DOM *gcdapi.DOM // DOM API DOMDebugger *gcdapi.DOMDebugger // DOM Debugger API DOMSnapshot *gcdapi.DOMSnapshot DOMStorage *gcdapi.DOMStorage // DOM Storage API Emulation *gcdapi.Emulation EventBreakpoints *gcdapi.EventBreakpoints FedCm *gcdapi.FedCm Fetch *gcdapi.Fetch HeadlessExperimental *gcdapi.HeadlessExperimental HeapProfiler *gcdapi.HeapProfiler // HeapProfiler API IndexedDB *gcdapi.IndexedDB // IndexedDB API Input *gcdapi.Input // Why am i doing this, it's obvious what they are, I quit. Inspector *gcdapi.Inspector IO *gcdapi.IO LayerTree *gcdapi.LayerTree Log *gcdapi.Log Media *gcdapi.Media Memory *gcdapi.Memory Network *gcdapi.Network Overlay *gcdapi.Overlay Page *gcdapi.Page Performance *gcdapi.Performance // if stable channel you'll need to uncomment PerformanceTimeline *gcdapi.PerformanceTimeline Preload *gcdapi.Preload Profiler *gcdapi.Profiler Runtime *gcdapi.Runtime Schema *gcdapi.Schema Security *gcdapi.Security ServiceWorker *gcdapi.ServiceWorker Storage *gcdapi.Storage SystemInfo *gcdapi.SystemInfo TargetApi *gcdapi.Target // buh name collision Tracing *gcdapi.Tracing Tethering *gcdapi.Tethering WebAudio *gcdapi.WebAudio WebAuthn *gcdapi.WebAuthn Target *TargetInfo // The target information see, TargetInfo // contains filtered or unexported fields }
ChromeTarget (Tab/Process). Messages are returned to callers via non-buffered channels. Helpfully, the remote debugger service uses id's so we can correlate which request should match which response. We use a map to store the id of the request which contains a reference to a gcdmessage.Message that holds the reply channel for the ChromeTarget to return the response to. Events are handled by mapping the method name to a function which takes a target and byte output. For now, callers will need to unmarshall the types themselves.
func (*ChromeTarget) GetApiTimeout ¶
func (c *ChromeTarget) GetApiTimeout() time.Duration
GetApiTimeout used by gcdmessage.SendCustomReturn and gcdmessage.SendDefaultRequest to timeout an API call if chrome hasn't responded to us in apiTimeout time.
func (*ChromeTarget) GetDoneCh ¶
func (c *ChromeTarget) GetDoneCh() chan struct{}
GetDoneCh channel used to signal any pending SendDefaultRequest and SendCustomReturn that we are exiting so we don't block goroutines from exiting.
func (*ChromeTarget) GetId ¶
func (c *ChromeTarget) GetId() int64
GetId increments the Id so we can synchronize our request/responses internally
func (*ChromeTarget) GetSendCh ¶
func (c *ChromeTarget) GetSendCh() chan *gcdmessage.Message
GetSendCh the channel used for API components to send back to use
func (*ChromeTarget) SendCustomReturn ¶ added in v2.1.2
func (c *ChromeTarget) SendCustomReturn(ctx context.Context, paramRequest *gcdmessage.ParamRequest) (*gcdmessage.Message, error)
SendCustomReturn takes in a ParamRequest and gives back a response channel so the caller can decode as necessary.
func (*ChromeTarget) SendDefaultRequest ¶ added in v2.1.2
func (c *ChromeTarget) SendDefaultRequest(ctx context.Context, paramRequest *gcdmessage.ParamRequest) (*gcdmessage.ChromeResponse, error)
SendDefaultRequest sends a generic request that gets back a generic response, or error. This returns a ChromeResponse object.
func (*ChromeTarget) SetApiTimeout ¶
func (c *ChromeTarget) SetApiTimeout(timeout time.Duration)
SetApiTimeout for how long we should wait before giving up gcdmessages. In the highly unusable (but it has occurred) event that chrome does not respond to one of our messages, we should be able to return from gcdmessage functions.
func (*ChromeTarget) Subscribe ¶
func (c *ChromeTarget) Subscribe(method string, callback func(*ChromeTarget, []byte))
Subscribe Events, you must know the method name, such as Page.loadFiredEvent, and bind a function which takes a ChromeTarget (us) and the raw JSON byte data for that event.
func (*ChromeTarget) Unsubscribe ¶
func (c *ChromeTarget) Unsubscribe(method string)
Unsubscribe the handler for no longer receiving events.
type DebugLogger ¶ added in v2.1.1
type DebugLogger struct{}
func (DebugLogger) Println ¶ added in v2.1.1
func (l DebugLogger) Println(args ...interface{})
type Dialer ¶ added in v2.1.1
type Dialer interface {
DialContext(ctx context.Context, network, address string) (net.Conn, error)
}
Dialer interface for WebSocket connection
type ErrBadHandshake ¶ added in v2.1.1
ErrBadHandshake type
func (*ErrBadHandshake) Error ¶ added in v2.1.1
func (e *ErrBadHandshake) Error() string
type Gcd ¶
type Gcd struct {
// contains filtered or unexported fields
}
The Google Chrome Debugger
func (*Gcd) ActivateTab ¶
func (c *Gcd) ActivateTab(target *ChromeTarget) error
ActivateTab (focus) the tab.
func (*Gcd) CloseTab ¶
func (c *Gcd) CloseTab(target *ChromeTarget) error
CloseTab closes the target tab.
func (*Gcd) ConnectToInstance ¶
ConnectToInstance connects to a running chrome instance without starting a local process Host - The host destination. Port - The port to listen on.
func (*Gcd) GetNewTargets ¶
func (c *Gcd) GetNewTargets(knownIds map[string]struct{}) ([]*ChromeTarget, error)
GetNewTargets gets a list of current tabs and creates new chrome targets returning a list provided they weren't in the knownIds list. Note it is an error to attempt to create a new chrome target from one that already exists.
func (*Gcd) GetTargets ¶
func (c *Gcd) GetTargets() ([]*ChromeTarget, error)
GetTargets primary tabs/processes to work with. Each will have their own references to the underlying API components (such as Page, Debugger, DOM etc).
func (*Gcd) NewTab ¶
func (c *Gcd) NewTab() (*ChromeTarget, error)
NewTab a new empty tab, returns the chrome target.
func (*Gcd) StartProcess ¶
StartProcess the process exePath - the path to the executable userDir - the user directory to start from so we get a fresh profile port - The port to listen on.
type GcdBodyReadErr ¶
type GcdBodyReadErr struct {
Message string
}
When we get an error reading the body from the debugger api endpoint
func (*GcdBodyReadErr) Error ¶
func (g *GcdBodyReadErr) Error() string
type GcdDecodingErr ¶
type GcdDecodingErr struct {
Message string
}
Failure to unmarshal the JSON response from debugger API
func (*GcdDecodingErr) Error ¶
func (g *GcdDecodingErr) Error() string
type LogDiscarder ¶ added in v2.1.1
type LogDiscarder struct{}
func (LogDiscarder) Println ¶ added in v2.1.1
func (l LogDiscarder) Println(args ...interface{})
type OnChromeExitHandler ¶ added in v2.1.4
type TargetInfo ¶
type TargetInfo struct { Description string `json:"description"` DevtoolsFrontendUrl string `json:"devtoolsFrontendUrl"` FaviconUrl string `json:"faviconUrl"` Id string `json:"id"` Title string `json:"title"` Type string `json:"type"` Url string `json:"url"` WebSocketDebuggerUrl string `json:"webSocketDebuggerUrl"` }
TargetInfo defines the 'tab' or target for this chrome instance, can be multiple and background processes are included (not just visual tabs)
type TerminatedHandler ¶
type TerminatedHandler func(reason string)
type WebSocket ¶ added in v2.1.1
type WebSocket struct { // Dialer is usually used for proxy Dialer Dialer // contains filtered or unexported fields }
WebSocket client for chromium. It only implements a subset of WebSocket protocol. Limitation: https://bugs.chromium.org/p/chromium/issues/detail?id=1069431 Ref: https://tools.ietf.org/html/rfc6455