Skip to content

Puppeteer: resizeWindow() does not change window bounds #973

@hubidu

Description

@hubidu

What 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 puppeteer/puppeteer#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
    });    
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions