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
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).
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.
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 });
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 } });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With