Set pupeteer window size when running not headless (not viewport)

Bernhard picture Bernhard · Feb 8, 2018 · Viewed 18.7k times · Source

Is it somehow possible to set the browsers (Chrome[ium]) window size like the viewport size?

Setting only the viewport results in a unhandy appearance when the browser is not running headfully and I want to visually see what's going on within the browser instance.

So I would like something like below:

const browser = await puppeteer.launch({
      headless: false, // The browser is visible
      ignoreHTTPSErrors: true
}),
page = await browser.newPage();


// This is well explained in the API
await page.setViewport({
    width: options.width,
    height: options.height
});

// But is there something like this (careful this is dummy code)
browser.setWindowSize({
    width: options.width,
    height: options.height
});

Thanks for any help pointing me into the right direction

Answer

Everettss picture Everettss · Feb 8, 2018

You can set chrome window size during puppeteer.launch with flag --window-size

Here is usage in your example:

const browser = await puppeteer.launch({
    headless: false, // The browser is visible
    ignoreHTTPSErrors: true,
    args: [`--window-size=${options.width},${options.height}`] // new option
});