Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 657
Bernhard Avatar asked Feb 08 '18 08:02

Bernhard


People also ask

How do you change the page size on a puppeteer?

You can pass the --window-size flag as an argument to puppeteer. launch() to change the window size to your desired width and height . Then you can call the Chrome Devtools Protocol method Emulation. clearDeviceMetricsOverride to clear the overridden device metrics (including the default 800 x 600 viewport).

Does puppeteer need Chrome installed?

By default, Puppeteer downloads and uses a specific version of Chromium so its API is guaranteed to work out of the box. To use Puppeteer with a different version of Chrome or Chromium, pass in the executable's path when creating a Browser instance: const browser = await puppeteer.


2 Answers

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 }); 
like image 123
Everettss Avatar answered Sep 19 '22 03:09

Everettss


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       }     }); 
like image 45
Efren Valdez Avatar answered Sep 19 '22 03:09

Efren Valdez