Getting Started with ChromeDP
This article will walk you through the process of leveraging BrowserCat and ChromeDP for browser automation at scale.
Prerequisites
Before you get started, you’ll need to:
- Sign up for a free BrowserCat account.
- Create an API key.
- Install ChromeDP in your project…
go get -u github.com/chromedp/chromedp
Your first automation
The following script connects to a BrowserCat browser, navigate to a website, and print the page title.
With a little tweaking (and the chromedp docs), you can automate literally anything you can do in a real browser.
package main
import (
"context"
"log"
"github.com/chromedp/chromedp"
)
func main() {
bcatUrl := "wss://api.browsercat.com/connect?apiKey=<YOUR_API_KEY>"
allocatorContext, cancel := chromedp.NewRemoteAllocator(
context.Background(),
bcatUrl,
chromedp.NoModifyURL,
)
defer cancel()
ctx, cancel := chromedp.NewContext(allocatorContext)
defer cancel()
var title string
if err := chromedp.Run(ctx,
chromedp.Navigate("https://example.com"),
chromedp.Title(&title),
); err != nil {
log.Fatalf("Failed getting title of example.com: %v", err)
}
log.Println(title)
}
Configure the browser
It’s really easy to configure our browsers for your needs. Whether you want to connect to a specific region, set up a third-party proxy, or customize your browser launch args, we’ve got you covered.
See out browser config docs for more info.