Home

Awesome

About chromedp examples

This folder contains a variety of code examples for working with chromedp. The package documentation contains a number of simple examples which are self-contained, while this repository holds more complex examples which tend to require internet access or external components.

Please note that these examples may break occassionally. Additionally, since these examples are written for specific websites, there is a good chance that the current selectors, etc. break after the website they are written against changes.

While every effort is made to ensure that these examples are kept up-to-date, it is expected that the examples made available here may occasionally break.

To file issues, use the chromedp's issue tracker.

Building and Running an Example

You can build and run these examples in the usual Go way:

# retrieve examples
$ go get -u -d github.com/chromedp/examples

# run example <prog>
$ go run $GOPATH/src/github.com/chromedp/examples/<prog>/main.go

# build example <prog>
$ go build -o <prog> github.com/chromedp/examples/<prog> && ./<prog>

Available Examples

The following examples are currently available:

<!-- the following section is updated by running `go run gen.go` --> <!-- START EXAMPLES -->
ExampleDescription
clickuse a selector to click on an element
cookieset a HTTP cookie on requests
download_filedo headless file downloads
download_imagedo headless image downloads
emulateemulate a specific device such as an iPhone
evalevaluate javascript and retrieve the result
fastextract and render data from a page
forecastextract and render data from a page
geoipextract and render data from a page
headersadd extra HTTP headers to browser requests
keyssend key events to an element
latlonretrieve the latitude/longitude from google maps, using the browser's target events
logicmore complex logic beyond simple actions
multiuse headless-shell and a container (Docker, Podman, other)
pdfcapture a pdf of a page
proxyauthenticate a proxy server which requires authentication
remoteconnect to an existing Chrome DevTools instance using a remote WebSocket URL
screenshottake a screenshot of a specific element and of the entire browser viewport
submitfill out and submit a form
subtreepopulate and travel a subtree of the DOM
textextract text from a specific element
uploadupload a file on a form
visiblewait until an element is visible
<!-- END EXAMPLES -->

Contributing

Pull Requests and contributions to this project are encouraged and greatly welcomed! The chromedp project always needs new examples, and needs talented developers (such as yourself!) to submit fixes for the existing examples when they break (for example, when a website's layout/HTML changes).