Skip to content

More examples

The repository chromedp/examples has larger programs, each for one task. Almost all of them run on your computer with no internet. This table comes from the doc comment of each program.

The 46 programs of chromedp/examples v0.24.1. Run one with go run github.com/chromedp/examples/<name>@latest.

Program What it shows
click Use a selector to click on an element
console Read the console of a page and its uncaught exceptions with chromedp.Console
contexts See the JavaScript contexts that a tab already has, with chromedp.WithListener
cookie Set an HTTP cookie on requests
dialogs Handle the JavaScript dialogs of a page
distrust Check that a browser rejects the certificates of a compromised certificate authority
download_file Do headless file downloads
download_image Do headless image downloads
dragdrop Drag and drop with the actions DragAndDrop and DragAndDropXY
emulate Emulate a specific device such as an iPhone
eval Evaluate JavaScript and retrieve the result
eventsiter Listen to the events of a page with iterators
exposefunc Call Go functions from a page with chromedp.ExposeFunc
extension Install a browser extension, uBlock Origin Lite, into the browser that chromedp starts, and how to show that it blocks the ads of a page
fast Measure the speed of the internet connection and show the result in the terminal
forecast Render the weather forecast of a city in the terminal
frames Reach elements inside an iframe and inside a shadow root
geoip Look up the location of an IP address and show its map in the terminal
har Generate a HAR file from the network events of a page
headers Add extra HTTP headers to browser requests
intercept Block, mock and change the requests of a page with the Fetch domain
keys Send key events to an element
latlon Retrieve the latitude and the longitude of a map from the URL of the page with the navigation events of the page
logic Combine actions and Go code in a function that reads a list from a page
multi Use headless-shell and a container (Docker, Podman, other)
pdf Capture a PDF of a page
pdfoptions Print a page to PDF files with different options of chromedp.PrintToPDF
pdfstream Print a page to a PDF file with a stream
popups Work with the popups of a page and with several targets
proxy Authenticate to a proxy server that requires authentication
rawcall Send protocol commands that chromedp has no action for
remote Connect to an existing Chrome DevTools instance using a remote WebSocket URL
screencast Record the screen of a page as a series of JPEG images
screenshot Take a screenshot of a specific element and of the entire browser viewport
selectors Choose the elements of a page with the typed selectors
session Save the state of a session and restore it in another browser
structeval Evaluate JavaScript into typed Go values
submit Fill out and submit a form
subtree Populate and travel a subtree of the DOM
tabs Use several tabs of one browser
termcast Stream the screen of the browser to the terminal with terminal graphics
text Extract text from a specific element
timeline See the events of a page of every type in the order in which Chrome sent them
upload Upload a file on a form
visible Wait until an element is visible
workers Run many jobs at the same time in one browser with a pool of goroutines