Package chromedp is a faster, simpler way to drive browsers supporting the Chrome DevTools Protocol in Go using the without external dependencies (like Selenium or PhantomJS).
Install in the usual Go way:
go get -u github.com/chromedp/chromedp
Refer to the GoDoc page for the documentation and examples. The examples repository contains more complex scenarios.
I can't see any Chrome browser window
By default, it's run in headless mode. See DefaultExecAllocatorOptions, and
an example
to override said options.
I'm seeing "context canceled" errors
If the connection to the browser is dropped, the context will be cancelled, which can be an unexpected reason for this error. For example, if the browser is closed manually.
Chrome exits as soon as my Go program finishes
This is set up on Linux to avoid leaking resources. If you want Chrome to be a
long-running process, start it separately and connect to it via RemoteAllocator.
Execute an action results in "invalid context"
By default, a chromedp context doesn't have an executor set up. You can specify one; see #326.
I can't use an
ActionwithRunbecause it returns many values
Wrap it with an ActionFunc:
chromedp.Run(ctx, chromedp.ActionFunc(func(ctx context.Context) error {
_, err := domain.SomeAction().Do(ctx)
return err
}))
- chromedp: A New Way to Drive the Web - GopherCon SG 2017 talk
- Chrome DevTools Protocol - Chrome DevTools Protocol Domain documentation
- chromedp examples - various
chromedpexamples github.com/chromedp/cdproto- GoDoc listing for the CDP domains used bychromedpgithub.com/chromedp/cdproto-gen- tool used to generatecdprotogithub.com/chromedp/chromedp-proxy- a simple CDP proxy for logging CDP clients and browsers