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();
})();
Unlock your potential: Puppeteer fundamentals series, all in one place!
To deepen your understanding of Puppeteer, explore our series of Answers below:
What is Puppeteer?
Learn about Puppeteer, a Node.js library that provides a high-level API for browser automation using headless Chrome or Chromium.
How to check for the browser version in Puppeteer
Discover how to retrieve the browser version using Puppeteer's browser.version()
method.
How to open the browser in headful mode with Puppeteer
Explore how to launch a visible browser instance by disabling the headless mode in Puppeteer.
How to get web page HTML with Puppeteer
Learn how to extract and manipulate a webpage’s HTML content using Puppeteer’s evaluate()
method.
What is the use of the setViewport method in Puppeteer?
Understand how setViewport()
customizes the browser’s viewport size for responsive testing and screenshots.
What is code coverage in Puppeteer?
Learn how to analyze unused JavaScript and CSS in web pages to optimize performance using Puppeteer’s coverage tool.
What is visual regression testing in Puppeteer?
Discover how Puppeteer can capture and compare screenshots to detect visual changes in web applications.
What is an accessibility test in Puppeteer?
Explore how Puppeteer, combined with accessibility tools like axe-core
, helps evaluate web accessibility compliance.
Free Resources