Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

resize browser with puppeteer

Is it possible to resize the browser window with puppeteer? I know there is page.setViewport, but is there anything like browser.setViewport? Maybe it sounds like there isn't much difference if you're running the headless version, but it can be useful if you're actually displaying the window, I'd like to do something like this:

const puppeteer = require("puppeteer");

(async () => {
let browser = await puppeteer.launch({
    headless: false
});
await browser.setViewport({
    width: 100,
    height: 100,
});
})();
like image 700
Paula Vega Avatar asked Oct 16 '25 11:10

Paula Vega


1 Answers

What I've found works for setting the browser size (but not the viewport size) is to set the following chrome command line switch when you're launching puppeteer:

await puppeteer.launch({
  headless: false,
  args: [
    '--window-size=X,Y'
  ]
});

All you have to do is substitute whatever resolution settings you want into the code instead of the X (width) and Y (height).

Update:
I've since located the following issue in which someone, rather helpfully, has provided their own resizeWindow() function which, apparently, does what you need. I've not tried it out so can't vouch for whether it works or not but it might be worth a try!

https://github.com/Codeception/CodeceptJS/issues/973

like image 173
AJC24 Avatar answered Oct 19 '25 01:10

AJC24



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!