Skip to content

chromedp

Drive Chrome from Go. chromedp talks to the browser over the Chrome DevTools Protocol, with no Node, Selenium or WebDriver.

chromedp is a Go package. It starts Chrome, or connects to a Chrome that runs already, and drives it: it loads pages, clicks, types, reads the page, takes screenshots, prints PDFs, and watches or changes the network. Programs use it to test web sites, to scrape them, and to make images and documents.

Play the recording below. It shows a program while it drives Chrome: the line of Go that runs, the page at that moment, and the messages of the protocol that the line sends.

The first page
The page at the end of the recording: A first program loads a page, reads it and clicks a button
A first program loads a page, reads it and clicks a button. A recording of tutorials/first-program/run.go in Chrome/158.0.8127.88. Step through it to see the line of Go, the page and the protocol messages of each step.
The steps of the recording
  1. line 15 if err := chromedp.Do(ctx, chromedp.Navigate(url)); err != nil {
  2. line 20 title, err := chromedp.Run(ctx, chromedp.Title())
  3. line 28 heading, err := chromedp.Run(ctx, chromedp.Text(chromedp.CSS("h1")))
  4. line 35 if err := chromedp.Do(ctx, chromedp.Click(chromedp.CSS("#greet"))); err != nil {
  5. line 41 greeting, err := chromedp.Run(ctx, chromedp.Text(chromedp.CSS("#greeting"), chromedp.NodeVisible))
  1. Install Go, Chrome and chromedp.
  2. Write your first program.
  3. Read the concepts: contexts, actions and selectors.
  4. Follow a tutorial: fill in a form, take screenshots and PDFs, read the console or intercept requests.

Every tutorial is a complete program in the repository of this site. A test runs each one in Chrome and checks its output.

/llms.txt lists every page as Markdown, and /llms-full.txt holds the whole site in one file. Add .md to the address of a page to get its Markdown, such as /start/install.md. See For coding agents.