/

How to Take a Screenshot Using Puppeteer

How to Take a Screenshot Using Puppeteer

Taking a screenshot using Puppeteer is a simple process. Once you have created the Puppeteer page object, you can use the screenshot() method to save a screenshot of the page.

Here is an example of how to save a screenshot as screenshot.jpg:

1
2
3
4
const page = await browser.newPage();
await page.screenshot({
path: 'screenshot.jpg'
});

To capture the entire page, you can add the fullPage option to the screenshot() method:

1
2
3
4
await page.screenshot({
path: 'screenshot.jpg',
fullPage: true
});

For a more comprehensive understanding of Puppeteer, you may refer to my full Puppeteer tutorial.

tags: [“puppeteer”, “screenshot”, “web development”, “browser automation”]