3

When new chrome headless mode is used the "--windows-size=width,height" argument doesn't work. For example: "--headless=new", "--window-size=1920,1080" Running tests with these arguments produces strange size screenshots: 1028x653 px

But with the old headless mode: "--headless", "--window-size=1920,1080" the screenshots size is OK: 1920x1080 px.

I can't use old mode, because the files downloading is not working in it anymore, here is the post about it, where using the new headless mode is suggest as a solution: Downloading with chrome headless and selenium

Dmitry Belykh
  • 31
  • 1
  • 2
  • I have found a solution. The problem with downloads in old headless mode (“headless=old”) was caused by me deleting the "download.default_directory" value from "userProfilePreferences" object in driver options in config file. – Dmitry Belykh Feb 13 '23 at 20:00
  • I have forgotten that this is necessary for the downloads to works with old headless mode. Bringing this value back fixed the problem with downloading files. So now I don’t need to care about the problem with window-size in new version headless mode (“headless=new”). At least the old headless mode will not be completely removed from chrome (I hove it will not happen for a long time ) – Dmitry Belykh Feb 13 '23 at 20:00
  • No, that doesn't help actually. It was OK on ver 109. After upgrading the Chrome to 110 version, the problem returns. – Dmitry Belykh Feb 14 '23 at 14:02
  • 1
    This is a bug being fixed in Chrome. You can see the status of the fix and the reasons here: https://bugs.chromium.org/p/chromium/issues/detail?id=1416398 – Chris S Feb 20 '23 at 18:41

3 Answers3

3

We came accross the same issue. Until the bug is solved, our workaroud is zooming out. We added argument force-device-scale-factor=0.75.

Hufi
  • 31
  • 2
0

Are you running your tests with a CI-Tool like Jenkins? I see a similar behavior (messing up the screen size) only with a central run on Jenkins, like always..local it works. If so I think it has to do with the system user the test is executed through a jenkins agent.

  • I am running tests locally and on Azure windows machines agents. Locally the difference is not so big, but still presents. – Dmitry Belykh Feb 14 '23 at 13:49
  • 1
    1904 x 890 - that is actual window-size for local run. And it perfectly OK with old headless mode. Except for the files downloads, which don't work at all (( – Dmitry Belykh Feb 14 '23 at 14:05
0

I faced this exact problem! Luckily I found a workaround! For java instead of --window-size=1920,1080 I did:

driver.manage().window().setSize(new Dimension(1920, 1080));

I also removed screen maximisation and it worked for me!

Please try above code or it's equivalent for the language you are using selenium with!

P.S.: I'm running selenium with xvfb! so if you have issues with screen size, you might look into that

bitwiseBro
  • 19
  • 6