In Puppeteer, you can set the viewport size by using the setViewport
method on the Page
object. Here's an example on how to set the viewport size to 1200x800:
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.setViewport({ width: 1200, height: 800 });
// Continue with your code...
await browser.close();
})();
In this example, setViewport
is called on the page
object with an object that contains the desired width and height of the viewport. You can adjust these values to set a different viewport size for your Puppeteer script.