Top Related Projects
A faster, simpler way to drive browsers supporting the Chrome DevTools Protocol.
Playwright for Go a browser automation library to control Chromium, Firefox and WebKit with a single API.
Selenium Hub successor running browsers within containers. Scalable, immutable, self hosted Selenium-Grid on any platform with single binary.
Selenium/Webdriver client for Go
Quick Overview
Rod is a high-level Chrome DevTools Protocol driver for web automation and scraping. It provides a concise and expressive API for controlling headless browsers, making it easier to automate web interactions, testing, and data extraction in Go.
Pros
- Simple and intuitive API for browser automation
- Lightweight and fast execution compared to some alternatives
- Built-in support for concurrent operations and race detection
- Extensive documentation and examples
Cons
- Limited browser support (primarily focused on Chrome/Chromium)
- May require more setup compared to higher-level frameworks
- Learning curve for users new to browser automation concepts
- Potential instability with rapid Chrome updates
Code Examples
- Navigate to a page and take a screenshot:
package main
import (
"github.com/go-rod/rod"
)
func main() {
page := rod.New().MustConnect().MustPage("https://example.com")
page.MustScreenshot("screenshot.png")
}
- Fill out a form and submit:
page := rod.New().MustConnect().MustPage("https://example.com/form")
page.MustElement("#username").MustInput("myuser")
page.MustElement("#password").MustInput("mypass")
page.MustElement("button[type=submit]").MustClick()
- Wait for an element to appear and extract its text:
page := rod.New().MustConnect().MustPage("https://example.com")
el := page.MustElement("#dynamic-content").MustWaitVisible()
text := el.MustText()
Getting Started
To use Rod in your Go project:
-
Install Rod:
go get github.com/go-rod/rod
-
Import Rod in your Go file:
import "github.com/go-rod/rod"
-
Create a basic script:
package main import ( "fmt" "github.com/go-rod/rod" ) func main() { page := rod.New().MustConnect().MustPage("https://example.com") title := page.MustInfo().Title fmt.Println("Page title:", title) }
-
Run your script:
go run your_script.go
Competitor Comparisons
A faster, simpler way to drive browsers supporting the Chrome DevTools Protocol.
Pros of chromedp
- More mature and established project with a larger community
- Extensive documentation and examples available
- Better support for complex JavaScript execution
Cons of chromedp
- Steeper learning curve due to more complex API
- Slower development cycle and less frequent updates
- Higher memory usage in some scenarios
Code Comparison
rod:
page := rod.New().MustConnect().MustPage("https://example.com")
page.MustElement("#button").MustClick()
text := page.MustElement("#result").MustText()
chromedp:
ctx, cancel := chromedp.NewContext(context.Background())
defer cancel()
var text string
err := chromedp.Run(ctx,
chromedp.Navigate("https://example.com"),
chromedp.Click("#button", chromedp.NodeVisible),
chromedp.Text("#result", &text),
)
Key Differences
- rod offers a more fluent and chainable API, while chromedp uses a context-based approach
- rod's error handling is based on panics and recovery, whereas chromedp uses traditional error returns
- rod provides a simpler setup process, while chromedp requires more configuration
Use Cases
- rod: Ideal for quick prototyping and simpler web automation tasks
- chromedp: Better suited for complex, large-scale web scraping and testing projects
Both libraries are powerful tools for web automation in Go, with rod focusing on simplicity and ease of use, while chromedp offers more advanced features and control at the cost of complexity.
Playwright for Go a browser automation library to control Chromium, Firefox and WebKit with a single API.
Pros of Playwright-go
- Built on top of the popular Playwright framework, benefiting from its cross-browser support and extensive features
- Provides a more idiomatic Go API compared to Rod's lower-level approach
- Offers better documentation and examples for Go developers
Cons of Playwright-go
- Requires installation of browser binaries, which can be cumbersome in some environments
- May have slower performance due to the additional layer of abstraction over Playwright
Code Comparison
Playwright-go:
pw, _ := playwright.Run()
browser, _ := pw.Chromium.Launch()
page, _ := browser.NewPage()
page.Goto("https://example.com")
title, _ := page.Title()
Rod:
browser := rod.New().MustConnect()
page := browser.MustPage("https://example.com")
title := page.MustInfo().Title
Both libraries provide similar functionality, but Rod's API is more concise and uses method chaining. Playwright-go follows a more traditional error-handling approach, which may be preferred by some Go developers.
Selenium Hub successor running browsers within containers. Scalable, immutable, self hosted Selenium-Grid on any platform with single binary.
Pros of Selenoid
- Supports multiple browser types (Chrome, Firefox, Opera) and versions
- Provides video recording and live browser screen streaming
- Offers a user-friendly UI for managing and monitoring sessions
Cons of Selenoid
- Requires more complex setup and infrastructure (Docker, configuration files)
- Limited to Selenium WebDriver protocol, less flexible for custom automation
Code Comparison
Rod:
page := rod.New().MustConnect().MustPage("https://example.com")
page.MustElement("#button").MustClick()
Selenoid (using Selenium WebDriver):
driver = webdriver.Remote(
command_executor='http://localhost:4444/wd/hub',
desired_capabilities={'browserName': 'chrome'}
)
driver.get("https://example.com")
driver.find_element_by_id("button").click()
Key Differences
- Rod is a lightweight, Go-based browser automation library, while Selenoid is a powerful Selenium hub implementation
- Rod offers a simpler setup and usage, ideal for quick automation tasks
- Selenoid provides more robust features for large-scale testing environments and cross-browser testing
Both tools have their strengths, and the choice depends on specific project requirements, team expertise, and scalability needs.
Selenium/Webdriver client for Go
Pros of Selenium
- Mature and widely adopted in the industry
- Supports multiple browsers (Chrome, Firefox, Safari, etc.)
- Extensive documentation and community support
Cons of Selenium
- Slower execution compared to Rod
- More complex setup and configuration
- Heavier resource usage
Code Comparison
Selenium:
driver, _ := selenium.NewRemote(caps, "")
driver.Get("https://example.com")
element, _ := driver.FindElement(selenium.ByCSSSelector, "#button")
element.Click()
Rod:
page := rod.New().MustConnect().MustPage("https://example.com")
page.MustElement("#button").MustClick()
Key Differences
- Rod is designed specifically for Go, while Selenium has bindings for multiple languages
- Rod offers a more concise API, resulting in less boilerplate code
- Selenium provides better cross-browser compatibility
- Rod has built-in support for headless browsers, while Selenium requires additional configuration
Use Cases
- Choose Selenium for projects requiring broad browser support and established industry practices
- Opt for Rod in Go-specific projects prioritizing speed and simplicity
Both libraries serve web automation needs, but Rod may be more appealing for Go developers seeking a lightweight, fast solution, while Selenium remains a solid choice for cross-language, multi-browser projects.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Overview
Documentation | API reference | FAQ
Rod is a high-level driver directly based on DevTools Protocol. It's designed for web automation and scraping for both high-level and low-level use, senior developers can use the low-level packages and functions to easily customize or build up their own version of Rod, the high-level functions are just examples to build a default version of Rod.
Features
- Chained context design, intuitive to timeout or cancel the long-running task
- Auto-wait elements to be ready
- Debugging friendly, auto input tracing, remote monitoring headless browser
- Thread-safe for all operations
- Automatically find or download browser
- High-level helpers like WaitStable, WaitRequestIdle, HijackRequests, WaitDownload, etc
- Two-step WaitEvent design, never miss an event (how it works)
- Correctly handles nested iframes or shadow DOMs
- No zombie browser process after the crash (how it works)
- CI enforced 100% test coverage
Examples
Please check the examples_test.go file first, then check the examples folder.
For more detailed examples, please search the unit tests.
Such as the usage of method HandleAuth
, you can search all the *_test.go
files that contain HandleAuth
,
for example, use GitHub online search in repository.
You can also search the GitHub issues or discussions,
a lot of usage examples are recorded there.
Here is a comparison of the examples between rod and Chromedp.
If you have questions, please raise an issues/discussions or join the chat room.
Join us
Your help is more than welcome! Even just open an issue to ask a question may greatly help others.
Please read How To Ask Questions The Smart Way before you ask questions.
We use GitHub Projects to manage tasks, you can see the priority and progress of the issues here.
If you want to contribute please read the Contributor Guide.
Top Related Projects
A faster, simpler way to drive browsers supporting the Chrome DevTools Protocol.
Playwright for Go a browser automation library to control Chromium, Firefox and WebKit with a single API.
Selenium Hub successor running browsers within containers. Scalable, immutable, self hosted Selenium-Grid on any platform with single binary.
Selenium/Webdriver client for Go
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot