Skip to content

rodvschromedp

MIT 217 3 7,161
Sep 23 2022 v0.116.2(2024-07-12 11:52:28 ago)
13,387 6 - MIT
Mar 11 2022 58.1 thousand (month) v0.24.0(2026-11-18 05:04:28 ago)

Rod is a high-level Go library for browser automation built on the Chrome DevTools Protocol (CDP). It provides a simpler and more intuitive API compared to chromedp, making it easier to write browser automation and web scraping scripts in Go.

Key features include:

  • Simple API Rod's API is designed to be intuitive and requires less boilerplate than chromedp. Common operations like clicking, typing, and waiting are straightforward single-line calls.
  • Auto-wait Automatically waits for elements to be ready before interacting with them, reducing the need for explicit wait statements and making scripts more reliable.
  • Page pool Built-in page pool for managing multiple browser pages efficiently, useful for concurrent scraping tasks.
  • Stealth mode Includes a stealth plugin (rod/lib/launcher/flags) that can disable common automation detection vectors.
  • Element screenshots Can take screenshots of specific elements, not just full pages.
  • Network interception Supports hijacking network requests and responses for modification or monitoring.
  • Input emulation Realistic mouse and keyboard input emulation for interacting with complex web applications.

Rod is the recommended choice for new Go browser automation projects due to its simpler API and active maintenance. It is comparable to Playwright in terms of developer experience but native to the Go ecosystem.

ChromeDP is an open-source library for driving browsers using the Chrome DevTools Protocol (CDP) in the Go programming language. It is a high-level library that abstracts away the low-level details of interacting with the CDP and provides a simple, intuitive API for performing common browser automation tasks such as clicking elements, filling out forms, and taking screenshots.

ChromeDP also supports parallel execution of browser tasks, making it well-suited for large-scale web scraping and testing applications. It is considered as one of the most popular Go package for automation and scraping tasks.

Highlights


cdpfast

Example Use


package main

import (
    "fmt"
    "github.com/go-rod/rod"
    "github.com/go-rod/rod/lib/launcher"
)

func main() {
    // Launch browser
    url := launcher.New().Headless(true).MustLaunch()
    browser := rod.New().ControlURL(url).MustConnect()
    defer browser.MustClose()

    // Navigate and auto-wait for the page to load
    page := browser.MustPage("https://example.com")
    page.MustWaitStable()

    // Find elements and extract text - auto-waits for element
    title := page.MustElement("h1").MustText()
    fmt.Println("Title:", title)

    // Fill in a form
    page.MustElement("input[name='search']").MustInput("web scraping")
    page.MustElement("button[type='submit']").MustClick()

    // Wait for results and extract
    page.MustWaitStable()
    results := page.MustElements(".result-item")
    for _, el := range results {
        text := el.MustText()
        href := el.MustElement("a").MustProperty("href").String()
        fmt.Printf("Result: %s (%s)\n", text, href)
    }

    // Take screenshot of specific element
    page.MustElement(".results").MustScreenshot("results.png")
}
package main

import (
  "context"
  "fmt"

  "github.com/chromedp/chromedp"
)

func main() {
  var title, firstParagraph string

  // create context
  ctx, cancel := chromedp.NewContext(context.Background())
  defer cancel()

  // run task list (a scraping scenario)
  err := chromedp.Run(ctx,
    // go to page
    chromedp.Navigate("https://www.example.com"),
    // wait for element to load
    chromedp.WaitVisible("body"),
    // extract text from an element (css selector)
    chromedp.Text("title", &title),
    // extract first paragraph element
    chromedp.First(chromedp.ByTagName("p"), &firstParagraph),
  )
  if err != nil {
    fmt.Println("error:", err)
    return
  }

  fmt.Printf("Title: %s\n", title)
  fmt.Printf("First paragraph: %s\n", firstParagraph)
}

Alternatives / Similar


Was this page helpful?