chromedp

package module
v0.0.0-...-b47709e Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2018 License: MIT Imports: 28 Imported by: 0

README

About chromedp Build Status Coverage Status

Package chromedp is a faster, simpler way to drive browsers in Go using the Chrome Debugging Protocol (for Chrome, Edge, Safari, etc) without external dependencies (ie, Selenium, PhantomJS, etc).

NOTE: chromedp's API is currently unstable, and may change at a moments notice. There are likely extremely bad bugs lurking in this code. CAVEAT USER.

Installation

Install in the usual way:

go get -u github.com/knq/chromedp

Usage

Below is a simple Google search performed using chromedp (taken from examples/simple):

This example shows logic for a simple search for a known website, clicking on the right link, and then taking a screenshot of a specific element on the loaded page and saving that to a local file on disk.

// examples/simple/main.go
package main

import (
	"context"
	"fmt"
	"io/ioutil"
	"log"
	"time"

	cdp "github.com/knq/chromedp"
	cdptypes "github.com/knq/chromedp/cdp"
)

func main() {
	var err error

	// create context
	ctxt, cancel := context.WithCancel(context.Background())
	defer cancel()

	// create chrome instance
	c, err := cdp.New(ctxt, cdp.WithLog(log.Printf))
	if err != nil {
		log.Fatal(err)
	}

	// run task list
	var site, res string
	err = c.Run(ctxt, googleSearch("site:brank.as", "Home", &site, &res))
	if err != nil {
		log.Fatal(err)
	}

	// shutdown chrome
	err = c.Shutdown(ctxt)
	if err != nil {
		log.Fatal(err)
	}

	// wait for chrome to finish
	err = c.Wait()
	if err != nil {
		log.Fatal(err)
	}

	log.Printf("saved screenshot from search result listing `%s` (%s)", res, site)
}

func googleSearch(q, text string, site, res *string) cdp.Tasks {
	var buf []byte
	sel := fmt.Sprintf(`//a[text()[contains(., '%s')]]`, text)
	return cdp.Tasks{
		cdp.Navigate(`https://www.google.com`),
		cdp.WaitVisible(`#hplogo`, cdp.ByID),
		cdp.SendKeys(`#lst-ib`, q+"\n", cdp.ByID),
		cdp.WaitVisible(`#res`, cdp.ByID),
		cdp.Text(sel, res),
		cdp.Click(sel),
		cdp.WaitVisible(`a[href="/brankas-for-business"]`, cdp.ByQuery),
		cdp.WaitNotVisible(`.preloader-content`, cdp.ByQuery),
		cdp.Location(site),
		cdp.ScrollIntoView(`.banner-section.third-section`, cdp.ByQuery),
		cdp.Sleep(2 * time.Second), // wait for animation to finish
		cdp.Screenshot(`.banner-section.third-section`, &buf, cdp.ByQuery),
		cdp.ActionFunc(func(context.Context, cdptypes.Handler) error {
			return ioutil.WriteFile("screenshot.png", buf, 0644)
		}),
	}
}

Please see the examples directory for some more examples, and please refer to the GoDoc API listing for a summary of the API and Actions.

TODO

  • Move timeouts to context (defaults)
  • Implement more query selector options (allow over riding context timeouts)
  • Contextual actions for "dry run" (or via an accumulator?)
  • Network loader / manager
  • Profiler

Documentation

Overview

Package chromedp is a high level Chrome Debugging Protocol domain manager that simplifies driving web browsers (Chrome, Safari, Edge, Android Web Views, and others) for scraping, unit testing, or profiling web pages.

chromedp requires no third-party dependencies (ie, Selenium), implementing the async Chrome Debugging Protocol natively.

Index

Constants

View Source
const (
	// DefaultNewTargetTimeout is the default time to wait for a new target to
	// be started.
	DefaultNewTargetTimeout = 3 * time.Second

	// DefaultCheckDuration is the default time to sleep between a check.
	DefaultCheckDuration = 50 * time.Millisecond

	// DefaultPoolStartPort is the default start port number.
	DefaultPoolStartPort = 9000

	// DefaultPoolEndPort is the default end port number.
	DefaultPoolEndPort = 10000
)

Variables

View Source
var (
	// ErrInvalidDimensions is the error returned when the retrieved box model is
	// invalid.
	ErrInvalidDimensions = errors.New("invalid dimensions")

	// ErrNoResults is the error returned when there are no matching nodes.
	ErrNoResults = errors.New("no results")

	// ErrHasResults is the error returned when there should not be any
	// matching nodes.
	ErrHasResults = errors.New("has results")

	// ErrNotVisible is the error returned when a non-visible node should be
	// visible.
	ErrNotVisible = errors.New("not visible")

	// ErrVisible is the error returned when a visible node should be
	// non-visible.
	ErrVisible = errors.New("visible")

	// ErrDisabled is the error returned when a disabled node should be
	// enabled.
	ErrDisabled = errors.New("disabled")

	// ErrNotSelected is the error returned when a non-selected node should be
	// selected.
	ErrNotSelected = errors.New("not selected")

	// ErrInvalidBoxModel is the error returned when the retrieved box model
	// data is invalid.
	ErrInvalidBoxModel = errors.New("invalid box model")
)

Error types.

Functions

func ButtonLeft

ButtonLeft is a mouse action option to set the button clicked as the left mouse button.

func ButtonMiddle

ButtonMiddle is a mouse action option to set the button clicked as the middle mouse button.

func ButtonNone

ButtonNone is a mouse action option to set the button clicked as none (used for mouse movements).

func ButtonRight

ButtonRight is a mouse action option to set the button clicked as the right mouse button.

func ByID

func ByID(s *Selector)

ByID is a query option to select a single element by their CSS #id.

func ByNodeID

func ByNodeID(s *Selector)

ByNodeID is a query option to select elements by their NodeIDs.

func ByQuery

func ByQuery(s *Selector)

ByQuery is a query option to select a single element using DOM.querySelector.

func ByQueryAll

func ByQueryAll(s *Selector)

ByQueryAll is a query option to select elements by DOM.querySelectorAll.

func BySearch

func BySearch(s *Selector)

BySearch is a query option via DOM.performSearch (works with both CSS and XPath queries).

func EvalAsValue

func EvalAsValue(p *rundom.EvaluateParams) *rundom.EvaluateParams

EvalAsValue is a evaluate option that will cause the evaluated script to encode the result of the expression as a JSON-encoded value.

func EvalIgnoreExceptions

func EvalIgnoreExceptions(p *rundom.EvaluateParams) *rundom.EvaluateParams

EvalIgnoreExceptions is a evaluate option that will cause script evaluation to ignore exceptions.

func EvalWithCommandLineAPI

func EvalWithCommandLineAPI(p *rundom.EvaluateParams) *rundom.EvaluateParams

EvalWithCommandLineAPI is an evaluate option to make the DevTools Command Line API available to the evaluated script.

Note: this should not be used with untrusted Javascript.

func NodeEnabled

func NodeEnabled(s *Selector)

NodeEnabled is a query option to wait until the element is enabled.

func NodeNotPresent

func NodeNotPresent(s *Selector)

NodeNotPresent is a query option to wait until no elements match are present matching the selector.

func NodeNotVisible

func NodeNotVisible(s *Selector)

NodeNotVisible is a query option to wait until the element is not visible.

func NodeReady

func NodeReady(s *Selector)

NodeReady is a query option to wait until the element is ready.

func NodeSelected

func NodeSelected(s *Selector)

NodeSelected is a query option to wait until the element is selected.

func NodeVisible

func NodeVisible(s *Selector)

NodeVisible is a query option to wait until the element is visible.

Types

type Action

type Action interface {
	// Do executes the action using the provided context and frame handler.
	Do(context.Context, cdp.Handler) error
}

Action is the common interface for an action that will be executed against a context and frame handler.

func AttributeValue

func AttributeValue(sel interface{}, name string, value *string, ok *bool, opts ...QueryOption) Action

AttributeValue retrieves the element attribute value for the first node matching the selector.

func Attributes

func Attributes(sel interface{}, attributes *map[string]string, opts ...QueryOption) Action

Attributes retrieves the element attributes for the first node matching the selector.

func Blur

func Blur(sel interface{}, opts ...QueryOption) Action

Blur unfocuses (blurs) the first node matching the selector.

func CaptureScreenshot

func CaptureScreenshot(res *[]byte) Action

CaptureScreenshot captures takes a full page screenshot.

func Clear

func Clear(sel interface{}, opts ...QueryOption) Action

Clear clears the values of any input/textarea nodes matching the selector.

func Click

func Click(sel interface{}, opts ...QueryOption) Action

Click sends a mouse click event to the first node matching the selector.

func ComputedStyle

func ComputedStyle(sel interface{}, style *[]*css.ComputedProperty, opts ...QueryOption) Action

ComputedStyle retrieves the computed style of the first node matching the selector.

func Dimensions

func Dimensions(sel interface{}, model **dom.BoxModel, opts ...QueryOption) Action

Dimensions retrieves the box model dimensions for the first node matching the selector.

func DoubleClick

func DoubleClick(sel interface{}, opts ...QueryOption) Action

DoubleClick sends a mouse double click event to the first node matching the selector.

func Evaluate

func Evaluate(expression string, res interface{}, opts ...EvaluateOption) Action

Evaluate is an action to evaluate the Javascript expression, unmarshaling the result of the script evaluation to res.

When res is a type other than *[]byte, or **chromedp/cdp/runtime.RemoteObject, then the result of the script evaluation will be returned "by value" (ie, JSON-encoded), and subsequently an attempt will be made to json.Unmarshal the script result to res.

Otherwise, when res is a *[]byte, the raw JSON-encoded value of the script result will be placed in res. Similarly, if res is a *runtime.RemoteObject, then res will be set to the low-level protocol type, and no attempt will be made to convert the result.

Note: any exception encountered will be returned as an error.

func EvaluateAsDevTools

func EvaluateAsDevTools(expression string, res interface{}, opts ...EvaluateOption) Action

EvaluateAsDevTools is an action that evaluates a Javascript expression as Chrome DevTools would, evaluating the expression in the "console" context, and making the Command Line API available to the script.

Note: this should not be used with untrusted Javascript.

func Focus

func Focus(sel interface{}, opts ...QueryOption) Action

Focus focuses the first node matching the selector.

func InnerHTML

func InnerHTML(sel interface{}, html *string, opts ...QueryOption) Action

InnerHTML retrieves the inner html of the first node matching the selector.

func JavascriptAttribute

func JavascriptAttribute(sel interface{}, name string, res interface{}, opts ...QueryOption) Action

JavascriptAttribute retrieves the Javascript attribute for the first node matching the selector.

func KeyAction

func KeyAction(keys string, opts ...KeyOption) Action

KeyAction will synthesize a keyDown, char, and keyUp event for each rune contained in keys along with any supplied key options.

Only well-known, "printable" characters will have char events synthesized.

Please see the chromedp/kb package for implementation details and the list of well-known keys.

func KeyActionNode

func KeyActionNode(n *cdp.Node, keys string, opts ...KeyOption) Action

KeyActionNode dispatches a key event on a node.

func Location

func Location(urlstr *string) Action

Location retrieves the document location.

func MatchedStyle

func MatchedStyle(sel interface{}, style **css.GetMatchedStylesForNodeReturns, opts ...QueryOption) Action

MatchedStyle retrieves the matched style information for the first node matching the selector.

func MouseAction

func MouseAction(typ input.MouseType, x, y int64, opts ...MouseOption) Action

MouseAction is a mouse action.

func MouseClickNode

func MouseClickNode(n *cdp.Node, opts ...MouseOption) Action

MouseClickNode dispatches a mouse left button click event at the center of a specified node.

Note that the window will be scrolled if the node is not within the window's viewport.

func MouseClickXY

func MouseClickXY(x, y int64, opts ...MouseOption) Action

MouseClickXY sends a left mouse button click (ie, mousePressed and mouseReleased event) at the X, Y location.

func Navigate(urlstr string) Action

Navigate navigates the current frame.

func NavigateBack() Action

NavigateBack navigates the current frame backwards in its history.

func NavigateForward() Action

NavigateForward navigates the current frame forwards in its history.

func NavigateToHistoryEntry(entryID int64) Action

NavigateToHistoryEntry is an action to navigate to the specified navigation entry.

func NavigationEntries(currentIndex *int64, entries *[]*page.NavigationEntry) Action

NavigationEntries is an action to retrieve the page's navigation history entries.

func NodeIDs

func NodeIDs(sel interface{}, ids *[]cdp.NodeID, opts ...QueryOption) Action

NodeIDs retrieves the node IDs matching the selector.

func Nodes

func Nodes(sel interface{}, nodes *[]*cdp.Node, opts ...QueryOption) Action

Nodes retrieves the document nodes matching the selector.

func OuterHTML

func OuterHTML(sel interface{}, html *string, opts ...QueryOption) Action

OuterHTML retrieves the outer html of the first node matching the selector.

func Query

func Query(sel interface{}, opts ...QueryOption) Action

Query is an action to query for document nodes match the specified sel and the supplied query options.

func QueryAfter

func QueryAfter(sel interface{}, f func(context.Context, cdp.Handler, ...*cdp.Node) error, opts ...QueryOption) Action

QueryAfter is an action that will match the specified sel using the supplied query options, and after the visibility conditions of the query have been met, will execute f.

func Reload

func Reload() Action

Reload reloads the current page.

func RemoveAttribute

func RemoveAttribute(sel interface{}, name string, opts ...QueryOption) Action

RemoveAttribute removes the element attribute with name from the first node matching the selector.

func Reset

func Reset(sel interface{}, opts ...QueryOption) Action

Reset is an action that resets the form of the first node matching the selector belongs to.

func Screenshot

func Screenshot(sel interface{}, picbuf *[]byte, opts ...QueryOption) Action

Screenshot takes a screenshot of the first node matching the selector.

func ScrollIntoView

func ScrollIntoView(sel interface{}, opts ...QueryOption) Action

ScrollIntoView scrolls the window to the first node matching the selector.

func SendKeys

func SendKeys(sel interface{}, v string, opts ...QueryOption) Action

SendKeys synthesizes the key up, char, and down events as needed for the runes in v, sending them to the first node matching the selector.

Note: when selector matches a input[type="file"] node, then dom.SetFileInputFiles is used to set the upload path of the input node to v.

func SetAttributeValue

func SetAttributeValue(sel interface{}, name, value string, opts ...QueryOption) Action

SetAttributeValue sets the element attribute with name to value for the first node matching the selector.

func SetAttributes

func SetAttributes(sel interface{}, attributes map[string]string, opts ...QueryOption) Action

SetAttributes sets the element attributes for the first node matching the selector.

func SetJavascriptAttribute

func SetJavascriptAttribute(sel interface{}, name, value string, opts ...QueryOption) Action

SetJavascriptAttribute sets the javascript attribute for the first node matching the selector.

func SetUploadFiles

func SetUploadFiles(sel interface{}, files []string, opts ...QueryOption) Action

SetUploadFiles sets the files to upload (ie, for a input[type="file"] node) for the first node matching the selector.

func SetValue

func SetValue(sel interface{}, value string, opts ...QueryOption) Action

SetValue sets the value of an element.

func Sleep

func Sleep(d time.Duration) Action

Sleep is an empty action that calls time.Sleep with the specified duration.

Note: this is a temporary action definition for convenience, and will likely be marked for deprecation in the future, after the remaining Actions have been able to be written/tested.

func Stop

func Stop() Action

Stop stops all navigation and pending resource retrieval.

func Submit

func Submit(sel interface{}, opts ...QueryOption) Action

Submit is an action that submits the form of the first node matching the selector belongs to.

func Text

func Text(sel interface{}, text *string, opts ...QueryOption) Action

Text retrieves the visible text of the first node matching the selector.

func Title

func Title(title *string) Action

Title retrieves the document title.

func Value

func Value(sel interface{}, value *string, opts ...QueryOption) Action

Value retrieves the value of the first node matching the selector.

func WaitEnabled

func WaitEnabled(sel interface{}, opts ...QueryOption) Action

WaitEnabled waits until the selected element is enabled (does not have attribute 'disabled').

func WaitEventLoad

func WaitEventLoad() Action

func WaitNotPresent

func WaitNotPresent(sel interface{}, opts ...QueryOption) Action

WaitNotPresent waits until no elements match the specified selector.

func WaitNotVisible

func WaitNotVisible(sel interface{}, opts ...QueryOption) Action

WaitNotVisible waits until the selected element is not visible.

func WaitReady

func WaitReady(sel interface{}, opts ...QueryOption) Action

WaitReady waits until the element is ready (ie, loaded by chromedp).

func WaitSelected

func WaitSelected(sel interface{}, opts ...QueryOption) Action

WaitSelected waits until the element is selected (has attribute 'selected').

func WaitVisible

func WaitVisible(sel interface{}, opts ...QueryOption) Action

WaitVisible waits until the selected element is visible.

type ActionFunc

type ActionFunc func(context.Context, cdp.Handler) error

ActionFunc is a adapter to allow the use of ordinary func's as an Action.

func (ActionFunc) Do

func (f ActionFunc) Do(ctxt context.Context, h cdp.Handler) error

Do executes the func f using the provided context and frame handler.

type CDP

type CDP struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

CDP contains information for managing a Chrome process runner, low level JSON and websocket client, and associated network, page, and DOM handling.

func New

func New(ctxt context.Context, opts ...Option) (*CDP, error)

New creates and starts a new CDP instance.

func (*CDP) AddTarget

func (c *CDP) AddTarget(ctxt context.Context, t client.Target)

AddTarget adds a target using the supplied context.

func (*CDP) CloseByID

func (c *CDP) CloseByID(id string) Action

CloseByID closes the Chrome target with the specified id.

func (*CDP) CloseByIndex

func (c *CDP) CloseByIndex(i int) Action

CloseByIndex closes the Chrome target with specified index i.

func (*CDP) GetHandlerByID

func (c *CDP) GetHandlerByID(id string) cdp.Handler

GetHandlerByID retrieves the domains manager for the specified target ID.

func (*CDP) GetHandlerByIndex

func (c *CDP) GetHandlerByIndex(i int) cdp.Handler

GetHandlerByIndex retrieves the domains manager for the specified index.

func (*CDP) ListTargets

func (c *CDP) ListTargets() []string

ListTargets returns the target IDs of the managed targets.

func (*CDP) NewTarget

func (c *CDP) NewTarget(id *string, opts ...client.Option) Action

NewTarget is an action that creates a new Chrome target, and sets it as the active target.

func (*CDP) Run

func (c *CDP) Run(ctxt context.Context, a Action) error

Run executes the action against the current target using the supplied context.

func (*CDP) SetHandler

func (c *CDP) SetHandler(i int) error

SetHandler sets the active handler to the target with the specified index.

func (*CDP) SetHandlerByID

func (c *CDP) SetHandlerByID(id string) error

SetHandlerByID sets the active target to the target with the specified id.

func (*CDP) SetTarget

func (c *CDP) SetTarget(i int) Action

SetTarget is an action that sets the active Chrome handler to the specified index i.

func (*CDP) SetTargetByID

func (c *CDP) SetTargetByID(id string) Action

SetTargetByID is an action that sets the active Chrome handler to the handler associated with the specified id.

func (*CDP) Shutdown

func (c *CDP) Shutdown(ctxt context.Context, opts ...client.Option) error

Shutdown closes all Chrome page handlers.

func (*CDP) Wait

func (c *CDP) Wait() error

Wait waits for the Chrome runner to terminate.

type EvaluateOption

type EvaluateOption func(*rundom.EvaluateParams) *rundom.EvaluateParams

EvaluateOption is the type for script evaluation options.

func EvalObjectGroup

func EvalObjectGroup(objectGroup string) EvaluateOption

EvalObjectGroup is a evaluate option to set the object group.

type KeyOption

KeyOption is a key action option.

func KeyModifiers

func KeyModifiers(modifiers ...input.Modifier) KeyOption

KeyModifiers is a key action option to add additional modifiers on the key press.

type LogFunc

type LogFunc func(string, ...interface{})

LogFunc is the common logging func type.

type MouseOption

MouseOption is a mouse action option.

func Button

func Button(btn string) MouseOption

Button is a mouse action option to set the button to click from a string.

func ButtonModifiers

func ButtonModifiers(modifiers ...input.Modifier) MouseOption

ButtonModifiers is a mouse action option to add additional input modifiers for a button click.

func ButtonType

func ButtonType(button input.ButtonType) MouseOption

ButtonType is a mouse action option to set the button to click.

func ClickCount

func ClickCount(n int) MouseOption

ClickCount is a mouse action option to set the click count.

type Option

type Option func(*CDP) error

Option is a Chrome Debugging Protocol option.

func WithConsolef

func WithConsolef(f LogFunc) Option

WithConsolef is a CDP option to specify a func to receive chrome log events.

Note: NOT YET IMPLEMENTED.

func WithDebugf

func WithDebugf(f LogFunc) Option

WithDebugf is a CDP option to specify a func to receive debug logging (ie, protocol information).

func WithErrorf

func WithErrorf(f LogFunc) Option

WithErrorf is a CDP option to specify a func to receive error logging.

func WithLog

func WithLog(f LogFunc) Option

WithLog is a CDP option that sets the logging, debugging, and error funcs to f.

func WithLogf

func WithLogf(f LogFunc) Option

WithLogf is a CDP option to specify a func to receive general logging.

func WithRunner

func WithRunner(r *runner.Runner) Option

WithRunner is a CDP option to specify the underlying Chrome runner to monitor for page handlers.

func WithRunnerOptions

func WithRunnerOptions(opts ...runner.CommandLineOption) Option

WithRunnerOptions is a CDP option to specify the options to pass to a newly created Chrome process runner.

func WithTargets

func WithTargets(watch <-chan client.Target) Option

WithTargets is a CDP option to specify the incoming targets to monitor for page handlers.

type Pool

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

Pool manages a pool of running Chrome processes.

func NewPool

func NewPool(opts ...PoolOption) (*Pool, error)

NewPool creates a new Chrome runner pool.

func (*Pool) Allocate

func (p *Pool) Allocate(ctxt context.Context, opts ...runner.CommandLineOption) (*Res, error)

Allocate creates a new process runner and returns it.

func (*Pool) Shutdown

func (p *Pool) Shutdown() error

Shutdown releases all the pool resources.

type PoolOption

type PoolOption func(*Pool) error

PoolOption is a pool option.

func PoolLog

func PoolLog(logf, debugf, errorf LogFunc) PoolOption

PoolLog is a pool option to set the logging to use for the pool.

func PortRange

func PortRange(start, end int) PoolOption

PortRange is a pool option to set the port range to use.

type QueryOption

type QueryOption func(*Selector)

QueryOption is a element query selector option.

func After

func After(f func(context.Context, cdp.Handler, ...*cdp.Node) error) QueryOption

After is a query option to set a func that will be executed after the wait has succeeded.

func AtLeast

func AtLeast(n int) QueryOption

AtLeast is a query option to wait until at least n elements are returned from the query selector.

func ByFunc

func ByFunc(f func(context.Context, cdp.Handler, *cdp.Node) ([]cdp.NodeID, error)) QueryOption

ByFunc is a query option to set the func used to select elements.

func WaitFunc

func WaitFunc(wait func(context.Context, cdp.Handler, *cdp.Node, ...cdp.NodeID) ([]*cdp.Node, error)) QueryOption

WaitFunc is a query option to set a custom wait func.

type Res

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

Res is a pool resource.

func (*Res) CDP

func (r *Res) CDP() *CDP

CDP returns the actual CDP instance.

func (*Res) Port

func (r *Res) Port() int

Port returns the allocated port for the pool resource.

func (*Res) Release

func (r *Res) Release() error

Release releases the pool resource.

func (*Res) Run

func (r *Res) Run(ctxt context.Context, a Action) error

Run runs an action.

func (*Res) URL

func (r *Res) URL() string

URL returns a formatted URL for the pool resource.

type Selector

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

Selector holds information pertaining to an element query select action.

func (*Selector) Do

func (s *Selector) Do(ctxt context.Context, h cdp.Handler) error

Do satisfies the Action interface.

type TargetHandler

type TargetHandler struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

TargetHandler manages a Chrome Debugging Protocol target.

func NewTargetHandler

func NewTargetHandler(t client.Target, logf, debugf, errorf LogFunc) (*TargetHandler, error)

NewTargetHandler creates a new handler for the specified client target.

func (*TargetHandler) Execute

func (h *TargetHandler) Execute(ctxt context.Context, commandType cdp.MethodType, params easyjson.Marshaler, res easyjson.Unmarshaler) error

Execute executes commandType against the endpoint passed to Run, using the provided context and params, decoding the result of the command to res.

func (*TargetHandler) GetRoot

func (h *TargetHandler) GetRoot(ctxt context.Context) (*cdp.Node, error)

GetRoot returns the current top level frame's root document node.

func (*TargetHandler) Listen

func (h *TargetHandler) Listen(eventTypes ...cdp.MethodType) <-chan interface{}

Listen creates a listener for the specified event types.

func (*TargetHandler) Release

func (h *TargetHandler) Release(ch <-chan interface{})

Release releases a channel returned from Listen.

func (*TargetHandler) ResetEventLoad

func (h *TargetHandler) ResetEventLoad()

ResetEventLoad resets the event load trigger returned by WaitEventLoad. It is called when a navigation is requested, so that the next load can take place.

func (*TargetHandler) Run

func (h *TargetHandler) Run(ctxt context.Context) error

Run starts the processing of commands and events of the client target provided to NewTargetHandler.

Callers can stop Run by closing the passed context.

func (*TargetHandler) SetActive

func (h *TargetHandler) SetActive(ctxt context.Context, id cdp.FrameID) error

SetActive sets the currently active frame after a successful navigation.

func (*TargetHandler) WaitEventLoad

func (h *TargetHandler) WaitEventLoad() <-chan struct{}

WaitEventLoad returns a channel which is closed when the page load event is fired, or the next TargetHandler.Run takes place.

func (*TargetHandler) WaitFrame

func (h *TargetHandler) WaitFrame(ctxt context.Context, id cdp.FrameID) (*cdp.Frame, error)

WaitFrame waits for a frame to be loaded using the provided context.

func (*TargetHandler) WaitNode

func (h *TargetHandler) WaitNode(ctxt context.Context, f *cdp.Frame, id cdp.NodeID) (*cdp.Node, error)

WaitNode waits for a node to be loaded using the provided context.

type Tasks

type Tasks []Action

Tasks is a sequential list of Actions that can be used as a single Action.

func (Tasks) Do

func (t Tasks) Do(ctxt context.Context, h cdp.Handler) error

Do executes the list of Actions sequentially, using the provided context and frame handler.

Directories

Path Synopsis
cdp
accessibility
Package accessibility provides the Chrome Debugging Protocol commands, types, and events for the Accessibility domain.
Package accessibility provides the Chrome Debugging Protocol commands, types, and events for the Accessibility domain.
animation
Package animation provides the Chrome Debugging Protocol commands, types, and events for the Animation domain.
Package animation provides the Chrome Debugging Protocol commands, types, and events for the Animation domain.
applicationcache
Package applicationcache provides the Chrome Debugging Protocol commands, types, and events for the ApplicationCache domain.
Package applicationcache provides the Chrome Debugging Protocol commands, types, and events for the ApplicationCache domain.
audits
Package audits provides the Chrome Debugging Protocol commands, types, and events for the Audits domain.
Package audits provides the Chrome Debugging Protocol commands, types, and events for the Audits domain.
browser
Package browser provides the Chrome Debugging Protocol commands, types, and events for the Browser domain.
Package browser provides the Chrome Debugging Protocol commands, types, and events for the Browser domain.
cachestorage
Package cachestorage provides the Chrome Debugging Protocol commands, types, and events for the CacheStorage domain.
Package cachestorage provides the Chrome Debugging Protocol commands, types, and events for the CacheStorage domain.
css
Package css provides the Chrome Debugging Protocol commands, types, and events for the CSS domain.
Package css provides the Chrome Debugging Protocol commands, types, and events for the CSS domain.
database
Package database provides the Chrome Debugging Protocol commands, types, and events for the Database domain.
Package database provides the Chrome Debugging Protocol commands, types, and events for the Database domain.
debugger
Package debugger provides the Chrome Debugging Protocol commands, types, and events for the Debugger domain.
Package debugger provides the Chrome Debugging Protocol commands, types, and events for the Debugger domain.
deviceorientation
Package deviceorientation provides the Chrome Debugging Protocol commands, types, and events for the DeviceOrientation domain.
Package deviceorientation provides the Chrome Debugging Protocol commands, types, and events for the DeviceOrientation domain.
dom
Package dom provides the Chrome Debugging Protocol commands, types, and events for the DOM domain.
Package dom provides the Chrome Debugging Protocol commands, types, and events for the DOM domain.
domdebugger
Package domdebugger provides the Chrome Debugging Protocol commands, types, and events for the DOMDebugger domain.
Package domdebugger provides the Chrome Debugging Protocol commands, types, and events for the DOMDebugger domain.
domsnapshot
Package domsnapshot provides the Chrome Debugging Protocol commands, types, and events for the DOMSnapshot domain.
Package domsnapshot provides the Chrome Debugging Protocol commands, types, and events for the DOMSnapshot domain.
domstorage
Package domstorage provides the Chrome Debugging Protocol commands, types, and events for the DOMStorage domain.
Package domstorage provides the Chrome Debugging Protocol commands, types, and events for the DOMStorage domain.
emulation
Package emulation provides the Chrome Debugging Protocol commands, types, and events for the Emulation domain.
Package emulation provides the Chrome Debugging Protocol commands, types, and events for the Emulation domain.
har
Package har provides the Chrome Debugging Protocol commands, types, and events for the HAR domain.
Package har provides the Chrome Debugging Protocol commands, types, and events for the HAR domain.
headlessexperimental
Package headlessexperimental provides the Chrome Debugging Protocol commands, types, and events for the HeadlessExperimental domain.
Package headlessexperimental provides the Chrome Debugging Protocol commands, types, and events for the HeadlessExperimental domain.
heapprofiler
Package heapprofiler provides the Chrome Debugging Protocol commands, types, and events for the HeapProfiler domain.
Package heapprofiler provides the Chrome Debugging Protocol commands, types, and events for the HeapProfiler domain.
indexeddb
Package indexeddb provides the Chrome Debugging Protocol commands, types, and events for the IndexedDB domain.
Package indexeddb provides the Chrome Debugging Protocol commands, types, and events for the IndexedDB domain.
input
Package input provides the Chrome Debugging Protocol commands, types, and events for the Input domain.
Package input provides the Chrome Debugging Protocol commands, types, and events for the Input domain.
inspector
Package inspector provides the Chrome Debugging Protocol commands, types, and events for the Inspector domain.
Package inspector provides the Chrome Debugging Protocol commands, types, and events for the Inspector domain.
io
Package io provides the Chrome Debugging Protocol commands, types, and events for the IO domain.
Package io provides the Chrome Debugging Protocol commands, types, and events for the IO domain.
layertree
Package layertree provides the Chrome Debugging Protocol commands, types, and events for the LayerTree domain.
Package layertree provides the Chrome Debugging Protocol commands, types, and events for the LayerTree domain.
log
Package log provides the Chrome Debugging Protocol commands, types, and events for the Log domain.
Package log provides the Chrome Debugging Protocol commands, types, and events for the Log domain.
memory
Package memory provides the Chrome Debugging Protocol commands, types, and events for the Memory domain.
Package memory provides the Chrome Debugging Protocol commands, types, and events for the Memory domain.
network
Package network provides the Chrome Debugging Protocol commands, types, and events for the Network domain.
Package network provides the Chrome Debugging Protocol commands, types, and events for the Network domain.
overlay
Package overlay provides the Chrome Debugging Protocol commands, types, and events for the Overlay domain.
Package overlay provides the Chrome Debugging Protocol commands, types, and events for the Overlay domain.
page
Package page provides the Chrome Debugging Protocol commands, types, and events for the Page domain.
Package page provides the Chrome Debugging Protocol commands, types, and events for the Page domain.
performance
Package performance provides the Chrome Debugging Protocol commands, types, and events for the Performance domain.
Package performance provides the Chrome Debugging Protocol commands, types, and events for the Performance domain.
profiler
Package profiler provides the Chrome Debugging Protocol commands, types, and events for the Profiler domain.
Package profiler provides the Chrome Debugging Protocol commands, types, and events for the Profiler domain.
runtime
Package runtime provides the Chrome Debugging Protocol commands, types, and events for the Runtime domain.
Package runtime provides the Chrome Debugging Protocol commands, types, and events for the Runtime domain.
security
Package security provides the Chrome Debugging Protocol commands, types, and events for the Security domain.
Package security provides the Chrome Debugging Protocol commands, types, and events for the Security domain.
serviceworker
Package serviceworker provides the Chrome Debugging Protocol commands, types, and events for the ServiceWorker domain.
Package serviceworker provides the Chrome Debugging Protocol commands, types, and events for the ServiceWorker domain.
storage
Package storage provides the Chrome Debugging Protocol commands, types, and events for the Storage domain.
Package storage provides the Chrome Debugging Protocol commands, types, and events for the Storage domain.
systeminfo
Package systeminfo provides the Chrome Debugging Protocol commands, types, and events for the SystemInfo domain.
Package systeminfo provides the Chrome Debugging Protocol commands, types, and events for the SystemInfo domain.
target
Package target provides the Chrome Debugging Protocol commands, types, and events for the Target domain.
Package target provides the Chrome Debugging Protocol commands, types, and events for the Target domain.
tethering
Package tethering provides the Chrome Debugging Protocol commands, types, and events for the Tethering domain.
Package tethering provides the Chrome Debugging Protocol commands, types, and events for the Tethering domain.
tracing
Package tracing provides the Chrome Debugging Protocol commands, types, and events for the Tracing domain.
Package tracing provides the Chrome Debugging Protocol commands, types, and events for the Tracing domain.
Package client provides the low level Chrome Debugging Protocol JSON types and related funcs.
Package client provides the low level Chrome Debugging Protocol JSON types and related funcs.
cmd
chromedp-gen
chromedp-gen is a tool to generate the low-level Chrome Debugging Protocol implementation types used by chromedp, based off Chrome's protocol.json.
chromedp-gen is a tool to generate the low-level Chrome Debugging Protocol implementation types used by chromedp, based off Chrome's protocol.json.
chromedp-gen/fixup
Package fixup modifies/alters/fixes and adds to the low level type definitions for the Chrome Debugging Protocol domains, as generated from protocol.json.
Package fixup modifies/alters/fixes and adds to the low level type definitions for the Chrome Debugging Protocol domains, as generated from protocol.json.
chromedp-gen/gen
Package gen takes the Chrome protocol domain definitions and applies the necessary code generation templates.
Package gen takes the Chrome protocol domain definitions and applies the necessary code generation templates.
chromedp-gen/internal
Package internal contains the types and util funcs common to the chromedp-gen command.
Package internal contains the types and util funcs common to the chromedp-gen command.
chromedp-gen/templates
Package templates contains the valyala/quicktemplate based code generation templates used by chromedp-gen.
Package templates contains the valyala/quicktemplate based code generation templates used by chromedp-gen.
chromedp-proxy
chromedp-proxy provides a cli utility that will proxy requests from a Chrome Debugging Protocol client to a application instance.
chromedp-proxy provides a cli utility that will proxy requests from a Chrome Debugging Protocol client to a application instance.
examples
logic
examples/logic/main.go
examples/logic/main.go
simple
examples/simple/main.go
examples/simple/main.go
Package kb provides keyboard mappings for Chrome DOM Keys for use with input events.
Package kb provides keyboard mappings for Chrome DOM Keys for use with input events.
Package runner provides a Chrome process runner.
Package runner provides a Chrome process runner.

Jump to

Keyboard shortcuts

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