Puppeteer is a Node library that provides a high-level API to control headless Chrome or Chromium browsers over the DevTools Protocol. It can also be configured to use full (non-headless) Chrome or Chromium.
A headless browser is a web browser, without a graphical user interface, that is mainly used for automated testing.
Puppeteer enables you to do most of the things that you can do manually in the browser. These features include:
To use Puppeteer in your project, run:
npm i puppeteer
When you install Puppeteer, it downloads a recent version of Chromium by default.
There is also the puppeteer-core
package, a version of Puppeteer that doesn’t download any browser by default. To install this package, run:
npm i puppeteer-core
Read more on the difference between puppeteer and puppeteer-core here.
An example code of using puppeteer that navigates to https://www.educative.io
, takes a screenshot, and saves as example.png
:
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://www.educative.io');
await page.screenshot({path: 'example.png'});
await browser.close();
})();