MCPcopy Create free account
hub / github.com/chromedp/examples

github.com/chromedp/examples @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
60 symbols 166 edges 24 files ⚖ MIT 15 documented · 25% ● updated 11d agov0.23.0 · 2026-11-05★ 1,265

Browse by type

⨍ Functions 57◇ Types & classes 3
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

About chromedp examples

chromedp logo

This repository holds 46 example programs for [chromedp][1], a Go package that drives Chrome through the Chrome DevTools Protocol. The package documentation has small examples that are self-contained. These programs are larger. Only the program fast needs the internet. The program extension needs the files of uBlock Origin Lite on disk. The program remote needs a Chrome with a debugging port, unless you use its flag -start.

[![Unit Tests][examples-ci-status]][examples-ci] [![Go Reference][goref-chromedp-status]][goref-chromedp] [![Releases][release-status]][releases] [![Discord Discussion][discord-status]][discord]

The programs use the typed API of chromedp v0.24.0 and cdproto v0.160.4. The file docs/API.md in the chromedp repository shows the old code and the new code side by side. The file docs/MIGRATION.md in the same folder lists every name that changed. See the decision for the port.

Build and run

The module needs Go 1.27. The packages chromedp, cdproto and termcast need only Go 1.25 or later. The module requires chromedp v0.24.0, cdproto v0.160.4 and termcast v0.3.0, and Go downloads them when you build a program. The programs use the package chromedp/remote, which is part of chromedp, for the flag -visible, which keeps the browser open, and for the remote program. They use termcast for the flag -visible-on-terminal.

The tags of this repository follow the tags of chromedp. The tag v0.24.0 holds programs that use chromedp v0.24, and a tag such as v0.24.1 is a later change in this repository.

chromedp starts the browser. It finds Chrome or Chromium on the PATH. If Chrome has another name, link it to the name google-chrome in a folder on the PATH. Run a program from the root of this repository:

# run the program <prog>, for example go run ./click
$ go run ./<prog>

# build the program <prog>
$ go build -o /tmp/<prog> ./<prog> && /tmp/<prog>

Every program accepts the flag -v. It prints the protocol messages between the program and the browser. Without -v, a program prints only its own output. For example, go run ./cookie -v shows the protocol messages. Run go run ./<prog> -h to see all flags of a program. Put the flags of a program after its folder, as in go run ./multi -out out <url>.

Every program except remote accepts the flag -visible. It shows the browser window instead of a headless browser, and it leaves the browser open when the program ends. The program prints the websocket address and the profile directory of the browser to the standard error. The browser stays running until you close its window, and the profile directory stays on disk until you delete it. To show the window with no flag, set the variable CHROMEDP_VISIBLEWINDOW=1. Any value other than an empty string, 0 and false turns it on. On Linux, a visible window needs DISPLAY or WAYLAND_DISPLAY. The remote program has no -visible flag, because it attaches to a browser that you started yourself. The flag -visible has no effect on the remote browser of forecast -remote. The tabs program works a little differently with -visible. It keeps every tab open and waits until you close the browser, and it does not leave the browser running. Its flag -tabs-in-one-window opens the tabs in one window, as real tabs, and switches between them with the protocol command Target.activateTarget. Without that flag, each tab opens in a window of its own. Try both with -visible to see the difference.

Some programs need arguments:

  • forecast needs the flag -q, for example go run ./forecast -q Jakarta.
  • geoip takes IP addresses, for example go run ./geoip 8.8.8.8.
  • multi takes URLs. See multi/README.md.
  • remote needs a running browser, or the flag -start. See remote/README.md.
  • extension needs the flag -ext with the files of uBlock Origin Lite.
  • upload uploads its own source file, so you can run it from any folder.

The programs download_file, download_image, emulate, har, pdf, pdfstream and screenshot write files into the current directory. The programs fast and forecast write a file only when you give the flag -out, and multi does so only with its flag -out. The programs pdfoptions and screencast write their files into a new temporary directory, or into the directory of their flag -out.

The programs

Example Description
click use a selector to click on an element
console read the console of a page and its uncaught exceptions with chromedp
contexts see the JavaScript contexts that a tab already has, with chromedp
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
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
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

The programs fast, forecast, geoip and remote draw an image in the terminal. Run them in a terminal that can show images. Most other programs have the flag -visible-on-terminal, which the section Draw the page in the terminal describes.

Draw the page in the terminal

Most programs take the flag -visible-on-terminal. It draws the page of the program in the terminal while the program runs, with terminal graphics (Kitty, iTerm2 or Sixel). The flag also works with a headless browser over ssh. The package [termcast][termcast] does this work. It uses the screencast of the Chrome DevTools Protocol and 4 frames each second by default. Use the flag `-t

Core symbols most depended-on inside this repo

browse all functions →

Shape

Function 56
Struct 3
Method 1

Languages

Go100%

Modules by API surface

geoip/main.go5 symbols
proxy/main.go4 symbols
gen.go4 symbols
forecast/main.go4 symbols
visible/main.go3 symbols
upload/main.go3 symbols
subtree/main.go3 symbols
screenshot/main.go3 symbols
multi/main.go3 symbols
logic/main.go3 symbols
keys/main.go3 symbols
headers/main.go3 symbols

For agents

$ claude mcp add examples \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page