Let’s check out:
- Selenium WebDriver client for Go.
- You can use the Go analog of Puppeteer.
- Playwright library.
- Or Screenshot API as a service.
They might overlap, but there is no best solution. Each depends on your use case and requirements.
Selenium WebDriver client for Go
Selenium is a well-known kid in the QA automation area, so it is easy to start taking screenshots if you plan to write automation tests or already do it.
Install Selenium WebDriver client for Go into your project:
Download the latest version ChromeDriver and the latest remote Selenium WebDriver standalone server, place them in the same source directory, and you are ready to Go:
If you just want to take one or two screenshots locally, the Selenium WebDriver client is not the best fit. As I wrote earlier, it better serves you already write automation tests with Selenium or plan to write them.
Go analog of Puppeteer
chromedp is the closest analog to Node.js Puppeteer in Go, a faster, more straightforward way to drive browsers supporting the Chrome DevTools Protocol in Go without external dependencies.
While you can also use chromedp
for automation testing, it is much light weighter and simpler than Selenium and allows any automation over the browser. Everything you can do manually with a browser, you can also do with chromedp
.
And it is super easy to use:
And then just:
It is very lightweight compared to Selenium and allows a broad spectrum for automation of the browser. You can use it for crawling, scrapping, taking screenshots, etc.
If you need the simplest way to take screenshots, you do not expect to take millions of them, and I would go with chromedp
. But if you want to take screenshots from different browsers or think about managing instances of browsers, there is a more straightforward way to go.
Playwright
Playwright is the best Go library to automate Chromium, Firefox, and WebKit with a unified API. It is built to enable cross-browser web automation.
If you want to take screenshots in different browsers, Playwright is the best choice.
Install the library with go get
:
Do not forget to install browser and OS dependencies:
And then take a screenshot:
Playwright
is the best choice. It is as powerful as chromedp
but allows you to run different browser instances if needed.
If you plan to take millions of screenshots and manage browser instances, you can do it yourself, but it is better to outsource to well-established services.
Screenshot API as a service
We specialize in taking screenshots and managing browser instances at scale. We provide a high-quality Go client to take screenshots and cover a variety of use cases.
Easy to install:
And easy to use:
If you feel that it is the best fit for you, feel free to sign up for our screenshot API and get the access key.
Summary
Pick the solution which suits your needs best. If you decide to go with our API, please ask any questions and mail us at support@screenshotone.com. And have a nice day 👋
By the way, you might also find interesting how to: