Documentation ¶
Index ¶
- Variables
- type ChromeTarget
- func (c *ChromeTarget) Debug(debug bool)
- func (c *ChromeTarget) DebugEvents(debug bool)
- 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) SetApiTimeout(timeout time.Duration)
- func (c *ChromeTarget) Subscribe(method string, callback func(*ChromeTarget, []byte))
- func (c *ChromeTarget) Unsubscribe(method string)
- type Gcd
- func (c *Gcd) ActivateTab(target *ChromeTarget) error
- func (c *Gcd) AddEnvironmentVars(vars []string)
- func (c *Gcd) AddFlags(flags []string)
- func (c *Gcd) CloseTab(target *ChromeTarget) error
- func (c *Gcd) ConnectToInstance(host string, port string) error
- func (c *Gcd) DeleteProfileOnExit()
- func (c *Gcd) ExitProcess() error
- func (c *Gcd) GetFirstTab() (*ChromeTarget, 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) SetTerminationHandler(handler TerminatedHandler)
- func (c *Gcd) SetTimeout(timeout time.Duration)
- 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 TargetInfo
- type TerminatedHandler
Constants ¶
This section is empty.
Variables ¶
var (
ErrNoTabAvailable = errors.New("no available tab found")
)
var GCDVERSION = "v1.0.15"
Functions ¶
This section is empty.
Types ¶
type ChromeTarget ¶
type ChromeTarget struct { // Chrome Debugger Domains Accessibility *gcdapi.Accessibility Animation *gcdapi.Animation ApplicationCache *gcdapi.ApplicationCache // application cache API 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 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 Memory *gcdapi.Memory Network *gcdapi.Network Overlay *gcdapi.Overlay Page *gcdapi.Page Performance *gcdapi.Performance // if stable channel you'll need to uncomment 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 Media *gcdapi.Media 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) Debug ¶
func (c *ChromeTarget) Debug(debug bool)
Debug for printing various debug information
func (*ChromeTarget) DebugEvents ¶
func (c *ChromeTarget) DebugEvents(debug bool)
DebugEvents to print out raw JSON event data when not Subscribed.
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) 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 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) AddEnvironmentVars ¶
AddEnvironmentVars for the chrome process, useful for Xvfb etc.
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) DeleteProfileOnExit ¶ added in v1.0.1
func (c *Gcd) DeleteProfileOnExit()
func (*Gcd) GetFirstTab ¶ added in v1.0.1
func (c *Gcd) GetFirstTab() (*ChromeTarget, error)
GetFirstTab returns the first tab created, to be called when first started, otherwise you will get a random tab returned.
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) SetTerminationHandler ¶
func (c *Gcd) SetTerminationHandler(handler TerminatedHandler)
Pass a handler to be notified when the chrome process exits.
func (*Gcd) SetTimeout ¶
SetTimeout for how long we should wait for debug port to become available.
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 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)