# Rod

> Drive Chrome from Go over the DevTools Protocol, with auto-waiting built in

- Category: Data & Labeling / Web Scraping & Crawling
- Language: Go
- Licence: MIT
- Repository: https://github.com/go-rod/rod
- Website: https://go-rod.github.io
- Canonical page: https://ai-tldr.dev/tools/go-rod/

## In short

Rod is a high-level Go driver built directly on the Chrome DevTools Protocol, designed for web automation and scraping. It sits in the Web Scraping & Crawling category of the Data & Labeling tools and is open-source, written in Go and licensed MIT. To get started: add the module.

## Overview

Rod is a high-level Go driver built directly on the Chrome DevTools Protocol, designed for web automation and scraping. It is deliberately two-layered: the low-level packages expose the protocol itself so you can build your own driver on top, and the high-level helpers are presented as one convenient assembly of those pieces rather than a closed framework. If you want a different set of ergonomics, you compose your own from the same parts.

The design decisions are aimed squarely at the failure modes of browser automation. Elements auto-wait to be ready, so you are not sprinkling sleeps through a scraper. The chained context design makes timing out or cancelling a long-running task natural. All operations are thread-safe. A two-step WaitEvent design means you never miss an event that fires between subscribing and acting. Nested iframes and shadow DOMs are handled correctly. And the browser process does not survive a crash of your program — Rod uses the leakless helper so there are no zombie Chrome processes left behind.

Practical helpers cover the things scrapers actually need: WaitStable for a page that has settled, WaitRequestIdle for network quiet, HijackRequests for intercepting and rewriting traffic, and WaitDownload for file downloads. Rod finds an installed browser or downloads one automatically through lib/launcher, and it is debugging-friendly, with automatic input tracing and remote monitoring of a headless browser so you can watch what your script is doing.

The project enforces 100% test coverage in CI, and the test suite doubles as the documentation: the README points you at examples_test.go first, then the lib/examples folder, and suggests searching the *_test.go files for any method you want a usage sample of. A side-by-side comparison with Chromedp lives in lib/examples/compare-chromedp. Rod is MIT-licensed, with API reference on pkg.go.dev and a Chinese API translation at go-rod/go-rod-chinese.

## What it does

- High-level Go API directly over the Chrome DevTools Protocol, with the low-level packages exposed for custom drivers
- Auto-waiting elements and a chained context design for clean timeouts and cancellation
- Helpers for real-world scraping: WaitStable, WaitRequestIdle, HijackRequests, WaitDownload
- Two-step WaitEvent design so events firing during subscription are never missed
- Correct handling of nested iframes and shadow DOMs
- Automatically finds or downloads a browser via lib/launcher; no zombie process after a crash
- Thread-safe across all operations, with input tracing and remote headless monitoring for debugging
- Queries by CSS selector, XPath and regex

## Getting started

Rod is a normal Go module. The README's own entry point is examples_test.go — start there, then lib/examples, then search the unit tests for the method you need.

1. Add the module

```bash
go get github.com/go-rod/rod
```

2. Open a page and read an element

   From the repository's Example_basic: launch a browser, open GitHub, type into the search box and pull text out of the result. Rod finds or downloads a browser for you.

```go
package main

import (
	"fmt"

	"github.com/go-rod/rod"
	"github.com/go-rod/rod/lib/input"
)

func main() {
	browser := rod.New().MustConnect()
	defer browser.MustClose()

	page := browser.MustPage("https://github.com").MustWaitStable()

	page.Keyboard.MustType(input.Slash)
	page.MustElement("#query-builder-test").MustInput("git").MustType(input.Enter)

	text := page.MustElementR("span", "most widely used").MustText()
	fmt.Println(text)
}
```

3. Evaluate JavaScript

   MustEval runs a JS function on the page; arguments are passed as JSON. Evaluated on an element, `this` is that DOM node.

```go
page.MustEval(`() => console.log("hello world")`)

fmt.Println("1 + 2 =", page.MustEval(`(a, b) => a + b`, 1, 2).Int())

fmt.Println(page.MustElement("title").MustEval(`() => this.innerText`).Str())
```

4. Find more usage

   Check examples_test.go and lib/examples, then search the repository's *_test.go files for a method — e.g. HandleAuth — to find a worked example. The comparison with Chromedp is in lib/examples/compare-chromedp.

## When to use it

- Scraping sites that only render under a real browser, from Go services
- Intercepting and rewriting network requests mid-page with HijackRequests
- End-to-end browser testing where flaky waits are the main source of failures
- Building a custom automation driver on the low-level CDP packages instead of accepting a framework's defaults
