Documentation
¶
Index ¶
- func ConnectWithContext(parent context.Context, chromeURL string, domains ...Domain) (context.Context, context.CancelFunc, error)
- func HasElement(ctx context.Context, sel string) (bool, error)
- func Navigate(ctx context.Context, pageURL string) error
- func PageLoadWaiterFunc(ctx context.Context, strict bool, timeout time.Duration) func() error
- func Text(ctx context.Context, sel string) (string, error)
- type Domain
- type NavHistory
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConnectWithContext ¶
func ConnectWithContext(parent context.Context, chromeURL string, domains ...Domain) (context.Context, context.CancelFunc, error)
ConnectWithContext establishes a connection with a Chrome process by Chrome DevTools Protocol, and activates requested domains.
If chromeURL is empty the function starts a new Chrome process by calling command "google-chrome" (must be in $PATH). If chromeURL is defined the function connects with a remote Chrome process that is accessible on this URL.
The function returns a context and cancelation function. You should use the context to execute a command in the connected Chrome process. The cancelation function closes the established connection. In the case when the connection established with a new Chrome process the function finishes the Chrome process.
func HasElement ¶
HasElement returns true when the current page of a Chrome process contains an element that matches a selector.
func Navigate ¶
Navigate navigates the current page of a Chrome process to an URL and waits for page loading finished.
The function differs from chromedp.Navigate() only that it waits for page loading finished.
See the function NewPageLoadingWaiter for details of waiting.
func PageLoadWaiterFunc ¶
PageLoadWaiterFunc returns a waiting function that waits for finishing of loading the current page.
The waiting function considers that loading is finished when events *network.EventLoadingFinished or *network.EventLoadingFailed is fired.
*network.EventLoadingFinished indicates successful page' loading. In this case the waiting function returns nil.
*network.EventLoadingFailed indicates a loading page's error. In this case the waiting function returns an error. When strict mode is used *network.EventLoadingFailed event does not generate an error, and the waiting function returns nil.
The waiting function return errors.Error with the kind errors.KindTimeout when a timeout exceeded (if timeout more than 0), and context.Canceled when a context canceled.
Types ¶
type Domain ¶
type Domain string
Domain is a Chrome DevTools Protocol domain.
const ( // DomainNetwork is the domain "Network". See https://chromedevtools.github.io/devtools-protocol/tot/Network. DomainNetwork Domain = "network" // DomainRuntime is the domain "Runtime". See https://chromedevtools.github.io/devtools-protocol/tot/Runtime. DomainRuntime Domain = "runtime" )
type NavHistory ¶
type NavHistory struct {
// contains filtered or unexported fields
}
NavHistory provides an access to page's navigation requests.
NavHistory doesn't use the browser history mechanism because of the browser doesn't store a navigation request in the history when a request failed with a network error, for example, net::ERR_CONNECTION_REFUSED.
func NewNavHistory ¶
func NewNavHistory(ctx context.Context) (*NavHistory, error)
NewNavHistory creates a new NavHistory and listens a Chrome process for navigation requests to fill the created NavHistory.
func (*NavHistory) Last ¶
func (h *NavHistory) Last() string
Last returns the last navigation request.
The last navigation request can be different from the current location of the page (see chromedp.Location()), for example, in the case of a redirect, or unavailable resource.
| example | the last navigation request | the current location |----------------------|-----------------------------|----------------------------- | without redirect | http://ac.me | http://ac.me | with redirect | http://ac.me/foo | http://ac.me/bar | unavailable resource | http://ac.me/unavailable | chrome-error://chromewebdata