For AI agents: a documentation index is available at /llms.txt
Skip to main content

Go (chromedp)

Browserless supports the chromedp Go library in beta. The usage mirrors a local setup: use the RemoteAllocator to connect to the Browserless API instead of a local browser. For available connection parameters, see connection URL patterns.

Prerequisites
  • A Browserless API token from your account dashboard
  • Go with the chromedp package installed (go get github.com/chromedp/chromedp)

Basic Usage

The example below navigates to example.com and retrieves the page title:

package main

import (
"context"
"flag"
"log"

"github.com/chromedp/chromedp"
)

func main() {
devtoolsWsURL := flag.String("devtools-ws-url", "wss://production-sfo.browserless.io?token=YOUR_API_TOKEN_HERE", "DevTools WebSsocket URL")
flag.Parse()

allocatorContext, cancel := chromedp.NewRemoteAllocator(context.Background(), *devtoolsWsURL,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("Got title of:", title)
}

For launch options you can pass as query parameters, see launch parameters. To learn more about session management and reconnection, see session management.

FAQ & Troubleshooting

Why am I getting a 403 Forbidden error?

Your API token is missing or expired. Pass it as a ?token= query parameter in the WebSocket or HTTP URL. Verify the token in your account dashboard.

My script works locally but fails on Browserless

Local browser settings may differ from the Browserless environment. Use launch parameters to match your local setup (viewport, user agent, timezone). See launch parameters for the full list.

Next steps