Today, there are many options to make screenshots of any URL with JavaScript or TypeScript (Node.js):
- Selenium for JavaScript.
- You can use 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
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:
And then:
If you just want to take one or two screenshots locally, Selenium is not the best fit. As I wrote earlier, it better serves you already write automation tests with Selenium or plan to write them.
Puppeteer
It is a Node library that interacts with browsers that support Chrome DevTools Protocol (CDP). It is not only Chrome and Chromium, but Firefox also has partial support of CDP.
The Chrome DevTools Protocol was developed to manage, debug and inspect Chromium and Chrome at the low level.
So, think of Puppeteer high-level API over Chrome DevTools Protocol which allows you to do everything in the browser that you can do manually:
- Extract data from a SPA, submit a form, type text, perform end-to-end UI testing and other automation-related tasks.
- Debug performance issues.
- Run, debug and test Chrome Extensions.
- Pre-render SPA to make a static site. But for Google SEO, it does not matter since Google renders JavaScript for every page nowadays.
- And guess what? Make screenshots and PDFs of pages.
Before starting to work with Puppeteer, let’s install it using npm:
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 Puppeteer
. But if you want to take screenshots from different browsers or think about managing instances of browsers, there are more straightforward ways to go.
If you wish, dive deeper into the different use cases on how to take screenshots with Puppeteer.
Playwright
Playwright is the best Java 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:
And then take a screenshot:
Playwright
is the best choice. It is as powerful and 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 Java 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: