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

34,746

Solution 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

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

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
});
Share:
34,746
Bernhard
Author by

Bernhard

Code to develop solutions and not to write code - I put a lot of emphasis on thinking along with measurable transparency and QA. I'm currently working on adaptive Industry 4.0 solutions and I'm happy to bring my accumulated experience and skills from electrical engineering (RWE Group & COBI as first MA and today part of Bosch Group) to the table. In addition to the technical skillset, it is important to me to understand problems and requirements of existing and potential new partners, to translate these into requirements and solutions that are convincing and are the cornerstone for long-term partnerships at eye level. I can bring in my experience especially in the area of "courage for new things" and on "the green field" and I am happy when such projects reach calmer waters and can be transferred into a regular operation - supervised by motivated teams.

Updated on February 12, 2022

Comments

  • Bernhard
    Bernhard over 2 years

    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