To take a screenshot of a webpage using Puppeteer, you can follow these steps:
npm install puppeteer
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://www.example.com');
await page.screenshot({ path: 'screenshot.png' });
await browser.close();
})();
You can also customize the screenshot by specifying additional options when calling the page.screenshot()
method. For example, you can set the viewport size, quality, and format of the screenshot. For more information, you can refer to the Puppeteer documentation: https://pptr.dev/#?product=Puppeteer&version=v22.0.3&show=api-pagescreenshotoptions