yukinying / chrome-headless-browser-docker

Continuously building Chrome Docker image for Linux.
https://store.docker.com/community/images/yukinying/chrome-headless-browser/tags
Apache License 2.0
373 stars 53 forks source link

Headless mode, cannot resize window #11

Closed abacaj closed 7 years ago

abacaj commented 7 years ago

Trying to resize window handle to generate larger screenshots:

Getting exception from selenium client: browser.Manage().Window.Size <- new Drawing.Size(1400, 900) Additional information: unknown error: cannot get automation extension

yukinying commented 7 years ago

Would passing "--window-size" to the chromeOptions args field works for you? See: http://peter.sh/experiments/chromium-command-line-switches/

abacaj commented 7 years ago

Seems to manifest when there is a different version of chrome vs chromedriver. Is that possible in these dockerfiles?

abacaj commented 7 years ago

I tried locally on my machine, using latest stable chrome and chromedriver 2.9 worked correctly when trying to resize window. Maybe resizing relies on xvfb? not sure about the details on this container.

yukinying commented 7 years ago

Do you mind sharing a minimal set of code that could reproduce the issue?

abacaj commented 7 years ago

The code I wrote is in javascript (node)

var webdriver = require("selenium-webdriver");

function getRemoteBrowser() {
    var activePlatform =  {
        "browserName": "chrome",
        "deviceName": "chrome",
        "platformName": "LINUX"
    };
    var browser = new webdriver.Builder()
        .withCapabilities(activePlatform)
        .usingServer('http://192.168.33.10:4444/wd/hub')
        .build();

    var driverWindow = driver.manage().window();

    driverWindow.maximize() // here

    return browser;
}
yukinying commented 7 years ago

According to https://bugs.chromium.org/p/chromedriver/issues/detail?id=1625#c39, headless mode does not support using extension to set the windows size, which seems to be what driver.manage().window().maximize() performed.

I believe that you can just use "--window-size" to set the dimension instead.

abacaj commented 7 years ago

Cool, thank you for finding that. I will use the arguments then.

alenadasan commented 6 years ago

"--window-size" not working either.

yukinying commented 6 years ago

Interesting. I am not able to reproduce it:

docker run --init -it --rm --name chrome --shm-size=1024m --cap-add=SYS_ADMIN \
  --entrypoint=/usr/bin/google-chrome-unstable \
  yukinying/chrome-headless-browser \
  --headless --disable-gpu --window-size=200,300 \
  --dump-dom http://howbigismybrowser.com/

And the result contains the correct dimension:

<div id="counter">
  <span class="num">200</span>
  <span id="divider"></span>
  <span class="num">300</span>
</div>