Documentation
¶
Index ¶
- Variables
- 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 WithFlags(flags []string) func(*Gcd)
- func WithInternalDebugMessages() func(*Gcd)
- func WithLogger(l Log) 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) 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) 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) 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 TargetInfo
- type TerminatedHandler
- type WebSocket
Constants ¶
This section is empty.
Variables ¶
var (
ErrNoTabAvailable = errors.New("no available tab found")
)
var GCDVERSION = "v2.1.1"
Functions ¶
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 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 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
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
PerformanceTimeline *gcdapi.PerformanceTimeline
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) 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 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) GetFirstTab ¶
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) 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 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
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
events
command
|
|
|
getdoc
command
|
|
|
loadpage
command
|
|
|
screenshot
command
|
|