Puppeteer: resizeWindow() does not change window bounds
See original GitHub issueWhat are you trying to achieve?
I want to resize the browser window
What do you get instead?
I get a bigger viewport size, but the browser window size stays the same.
See also https://github.com/GoogleChrome/puppeteer/issues/1183
Details
- CodeceptJS version: 1.1.5
- NodeJS Version: 8.9.4
- Operating System: Windows
- Puppeteer (1.0.0)
I would recommend considering the following code for the resizeWindow function which seems to work well
async resizeWindow(width, height) {
await this.page.setViewport({height, width});
// Window frame - probably OS and WM dependent.
height += 85;
// Any tab.
const {targetInfos: [{targetId}]} = await this.browser._connection.send(
'Target.getTargets'
);
// Tab window.
const {windowId} = await this.browser._connection.send(
'Browser.getWindowForTarget',
{targetId}
);
// Resize.
await this.browser._connection.send('Browser.setWindowBounds', {
bounds: {height, width},
windowId
});
}
Issue Analytics
- State:
- Created 6 years ago
- Reactions:18
- Comments:5
Top Results From Across the Web
Puppeteer: resizeWindow() does not change window bounds
I get a bigger viewport size, but the browser window size stays the same. See also puppeteer/puppeteer#1183. Details. CodeceptJS version: 1.1.5 ...
Read more >javascript - resize browser with puppeteer - Stack Overflow
What I've found works for setting the browser size (but not the viewport size) is to set the following chrome command line switch...
Read more >Puppeteer Window Size - CodeceptJS Community
resizeWindow just resizes the viewport for us. Some discussions say it is not possible to change window size with puppeteer and JS but...
Read more >Puppeteer - CodeceptJS
Puppeteer does not control the window of a browser so it can't adjust its real size. It also can't maximize a window.
Read more >Detecting and adjusting for a window resize - JavaScript
So now, I'm going to make my window smaller again and I'll refresh click on this and as I re-size the window, the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Here is a slightly improved version of @hubidu’s snippet:
I removed usages of private properties and call to ‘Target.getTargets’, because ‘Browser.getWindowForTarget’ returns the window with active CDP session (docs).
Modified version for puppeteer with slight code update (it works with chrome app mode):