There’s multiple Go drivers to connect to the Chrome Debugging Protocol in order to either run automated tests or to take responsive screenshots of websites. Let’s explore some of the options that are available for taking screenshots and how to use them from within Go.

Godet

Godet the smaller packages, which I started playing with in the beginning. I’m not actively maintaining it and it seems to have manually added API specs for the CDP. I’m only linking to my github repository because I’m still waiting for the PR to be accepted that allows the support for setDeviceMetrics.

Chromedp

Chromedp is a really cool project, very much geared towards automatic testing, but also supporting screenshots. There’s a wrapper around it on github: web2image that works as a command line uitility. Another bonus is that the package takes care of starting a chrome/chromium instance for you.

There’s a small caveat when you’re not 100% sure which Chrome/Chromium version you have installed at the moment though:

If your Chrome is not up to date with the protocol definition that is generated from the chromium source, this package will not work for you. You’ll need to make sure the version of Chromedp fits your install Chrome Headless version if the API changed recently.

because older Chromiums expect another parameter. However if you try to use that parameter with the up to date Go package, it will not compile, because the parameter is not part of that function any longer.

Summary

If you can get your service up and running or match the Chromium/chromedp versions successfully, it’s a great tool. Chromedp also is bound to keep up to date with the protocol as it changes and seems to be backed by a company that relies on it.