How can I set the browser window size when using `google-chrome --headless`?

I found it. Simply pass the --window-size command line argument to Google Chrome, for example --window-size=1920,1080.

In a Protractor configuration this would look like this:

capabilities: {
    browserName: 'chrome',
    chromeOptions: {
        args: ['headless', 'window-size=1920,1080']
    }
}

The cool thing is that the windows size is not limited to the current display. It is truly headless, meaning it can be as large as needed for the tests.

Java code:

options.addArguments("window-size=1920,1080");

I expand a bit more on this in Headless protractor not sharding tests.


Use the built-in Selenium function:

    aDriver.manage().window().setSize(new Dimension(width, height));

It works like a champ. I've used it for Firefox, Chrome (even headless), and Edge.