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

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



Solution 1:[1]

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
});

Solution 2:[2]

This resizes the window and the view area

const browser = await puppeteer.launch({
      headless: true,
      ignoreHTTPSErrors: true,
      args: [`--window-size=1920,1080`],
      defaultViewport: {
        width:1920,
        height:1080
      }
    });

Solution 3:[3]

If you want it to behave like a normal browser where it resizes the viewport to the window size. Then set the viewport to null

const browser = await puppeteer.launch(
{
    defaultViewport: null,
    headless: false
});

Solution 4:[4]

 const browser = await puppeteer.launch({
        headless: false,
        defaultViewport: null,
        args: ['--start-maximized'], // we can use '--start-fullscreen' || --start-maximized
    });

Solution 5:[5]

Set default viewport to null, which should resize like a normal browser.

const browser = await puppeteer.launch(
{
    defaultViewport: null,
    headless: false
});

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Everettss
Solution 2
Solution 3 John
Solution 4 Vigneshwaran Chandrasekaran
Solution 5 Jay Gurjar