gcd

package module
v2.3.4 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoTabAvailable = errors.New("no available tab found")
)
View Source
var GCDVERSION = "v2.3.1"

Functions

func WithChromeCmdOutput added in v2.2.3

func WithChromeCmdOutput(output io.Writer) func(*Gcd)

WithChromeCmdOutput will send the STDOUT and STDERR output of the chrome process to the provided stream

func WithContext added in v2.1.1

func WithContext(ctx context.Context) func(*Gcd)

func WithDebugPortTimeout added in v2.1.1

func WithDebugPortTimeout(timeout time.Duration) func(*Gcd)

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

func WithEnvironmentVars(vars []string) func(*Gcd)

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

func WithEventQueueSize(queueSize int) func(*Gcd)

WithEventQueueSize number of DevTool events to allow to queue up

func WithFlags added in v2.1.1

func WithFlags(flags []string) func(*Gcd)

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 WithLogger(l Log) func(*Gcd)

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) Init

func (c *ChromeTarget) Init()

Init all api objects

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

type ErrBadHandshake struct {
	*http.Response
}

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 NewChromeDebugger

func NewChromeDebugger(opts ...func(*Gcd)) *Gcd

Give it a friendly name.

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

func (c *Gcd) ConnectToInstance(host string, port string) error

ConnectToInstance connects to a running chrome instance without starting a local process Host - The host destination. Port - The port to listen on.

func (*Gcd) ExitProcess

func (c *Gcd) ExitProcess() error

ExitProcess kills the process

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) GetRevision

func (c *Gcd) GetRevision() string

GetRevision of chrome

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) Host

func (c *Gcd) Host() string

Host that the debugger is listening on

func (*Gcd) NewTab

func (c *Gcd) NewTab() (*ChromeTarget, error)

NewTab a new empty tab, returns the chrome target.

func (*Gcd) PID

func (c *Gcd) PID() int

PID of the started process

func (*Gcd) Port

func (c *Gcd) Port() string

Port that the debugger is listening on

func (*Gcd) StartProcess

func (c *Gcd) StartProcess(exePath, userDir, port string) error

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.

func (*Gcd) StartProcessCustom

func (c *Gcd) StartProcessCustom(cmd *exec.Cmd, userDir, port string) error

StartProcessCustom lets you pass in the exec.Cmd to use

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 Log added in v2.1.1

type Log interface {
	Println(args ...interface{})
}

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 OnChromeExitHandler func(profileDir string, err error)

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

func (*WebSocket) Connect added in v2.1.1

func (ws *WebSocket) Connect(ctx context.Context, wsURL string, header http.Header) error

Connect to browser

func (*WebSocket) Read added in v2.1.1

func (ws *WebSocket) Read() ([]byte, error)

Read a message from browser

func (*WebSocket) Send added in v2.1.1

func (ws *WebSocket) Send(msg []byte) error

Send a message to browser. Because we use zero-copy design, it will modify the content of the msg. It won't allocate new memory.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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