When I run a new page, I must specify size of the viewport using the setViewport function:
await page.setViewport({
width: 1920,
height: 108
Here is a way to do it at runtime by calling Page.setViewport() in headful and Browser.setWindowBounds() in headless via a Chrome Devtools Protocol session:
async function setWindowSize(page, width, height) {
if(headless) {
const session = await page.target().createCDPSession();
const {windowId} = await session.send('Browser.getWindowForTarget');
await session.send('Browser.setWindowBounds', {windowId, bounds: {width: width, height: height}});
await session.detach();
} else {
await page.setViewport({width: width, height: height});
}
}
See my comment on GitHub for more info.