Project: chromium Issues People Development process History Sign in
New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.
Issue 604324 Selenium support for headless
Starred by 110 users Project Member Reported by skyos...@chromium.org, Apr 18 2016 Back to list
Status: Assigned
Owner:
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Windows
Pri: 3
Type: Bug


Sign in to add a comment
This bug tracks the work needed to make it possible to use Headless Chrome as a back-end in Selenium
 
Labels: Proj-Headless
Labels: OS-Windows
Hi, is there any timeline for selenium support for headless chrome?
Blockedon: 612904
I think we can look at this after bug 612904 is done.
I already use selenium with the headless_shell like this (in Java):


HashMap<String,String> env = new HashMap<>();
env.put("CHROME_DEVEL_SANDBOX", "/home/paulo/headless_chrome/chrome-devel-sandbox");
ChromeDriverService cs = new ChromeDriverService.Builder()
        .withEnvironment(env)
        .usingDriverExecutable(new File(......))
        .build();
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
options.setBinary("/home/paulo/headless_chrome/headless_shell");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new ChromeDriver(cs,capabilities);


Does bug 612904 imply that headless_shell is going to disappear and be replaced by chrome called with a headless parameter?
No both headless_shell and a --headless for chrome will coexist.
I think headless shell will be around for a while longer, but longer term I think we should kill it in favor of everyone using Chrome proper with a --headless flag. The reason is that Chrome 1) auto-updates and 2) runs on more than just Linux.
Comment 8 by amo...@gmail.com, Sep 27 2016
Part of the appeal of using headless_shell is that it's lightweight and has a lot less lib dependencies than Chrome. Using the headless flag with Chrome and killing headless_shell would also kill that advantage if I read this correctly.
True, we'll still need 90% of the code in headless shell, so keeping the binary around too is not a huge burden. We'll keep your comments in mind.
Labels: HeadlessUpForGrabs
Cc: eseckler@chromium.org
Any progress? I run it with
            options.addArguments("headless");
            options.addArguments("start-maximized");
            options.addArguments("disable-gpu");
            options.addArguments("no-sandbox");
            options.addArguments("disable-popup-blocking");
            options.addArguments("v9");
            options.addArguments("screenshot");
            options.addArguments("always-authorize-plugins");
and got the following errors (hope it will help any others to find this issue) :

There were 2 errors:
  org.openqa.selenium.WebDriverException(unknown error: cannot get automation extension
from unknown error: page could not be found: chrome-extension://aapnijgdinlhnhlmodcfapnahmbfebeb/_generated_background_page.html
  (Session info: content shell=)
  (Driver info: chromedriver=2.27.440175 (9bc1d90b8bfa4dd181fbbf769a5eb5e575574320),platform=Linux 2.6.32-44-pve x86_64) (WARNING: The server did not provide any stacktrace information)
Cc: samu...@chromium.org
There are a few features of webdriver / chromedriver that aren't supported by headless at the moment. Extensions are one of them, and chromedriver uses an extension for some operations, e.g. to set the window size. Until we modify chromedriver/headless to support these operations, you can try to work around the restriction by avoiding these operations. (For window size, there's also a command line flag, e.g. --window-size=800x600, that might work for you instead.)
Thanks, it started to work with
            capabilities.setCapability("nativeEvents", false);
            capabilities.setCapability("takesScreenshot", false);
and removed browser.manage().window().maximize();
, but then failed on sendKeys call. Seems like keys and mouse events is also unsupported. Ok, I agree to wait.
To add to #c13, some things will work, some things won't. I've put together a doc listing some of the obvious things that are missing: https://docs.google.com/document/d/17VbJpJ9THEEsmy78Io3hbjHJs5dVy8eQ1kx9BNL6Ydo/edit?usp=sharing
Hey #c15 (samu...)

Could we add that window popups are not working with the headless_shell as well please? I didn't see that in the document. Not sure if its anything the team plan on addressing soon ?

You can verify with the following command;

headless_shell --remote-debugging-port=9222 --window-size=1280,1024 http://html.com/javascript/popup-windows/

Open the devtools on in a browser click on the link my popup under the section 'The Basics' - observe no errors/logs from either headless_shell or the devtools console

It isn't specific to that web page - but also on our internal app ran by the test suite which uses the pop windows for oauth(2) authorization flow. Driven by selenium webdriver chromedriver. It appears is it able to see the page content - but is unable to interact with the popup window.

I can create a bug but felt as you had a document with the things that won't work - that probably would be the place for now ? If not let me know.

Also thanks for your work on the headless_shell/chromium
Blockedon: 696439
#16: Sounds like something we should investigate. Filed https://crbug.com/696439.
Owner: jzfeng@chromium.org
Status: Assigned
Handed off to jzfeng@ who's going to start porting some of the features currently implemented by the ChromeDriver extension to DevTools.
Project Member Comment 20 by bugdroid1@chromium.org, Mar 14
Blocking: chromedriver:639
Project Member Comment 22 by bugdroid1@chromium.org, Mar 31
The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/d6cc35e9043b01bfffaf3164bee1c5310cdedcf7

commit d6cc35e9043b01bfffaf3164bee1c5310cdedcf7
Author: samuong <samuong@chromium.org>
Date: Fri Mar 31 04:37:36 2017

[chromedriver] Introduce chromeOptions.useAutomationExtension.

This allows clients to enable or disable the ChromeDriver automation extension.
It is currently true by default, but once we introduce DevTools commands to
replace the extension, we'll set this to false by default, and later remove it.

BUG=604324
TBR=stgao@chromium.org

Review-Url: https://codereview.chromium.org/2785413002
Cr-Commit-Position: refs/heads/master@{#461032}

[modify] https://crrev.com/d6cc35e9043b01bfffaf3164bee1c5310cdedcf7/chrome/test/chromedriver/capabilities.cc
[modify] https://crrev.com/d6cc35e9043b01bfffaf3164bee1c5310cdedcf7/chrome/test/chromedriver/capabilities.h
[modify] https://crrev.com/d6cc35e9043b01bfffaf3164bee1c5310cdedcf7/chrome/test/chromedriver/chrome_launcher.cc
[modify] https://crrev.com/d6cc35e9043b01bfffaf3164bee1c5310cdedcf7/chrome/test/chromedriver/test/run_py_tests.py

Project Member Comment 23 by bugdroid1@chromium.org, Apr 8
The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/24a8ad434aab59c8c8a08ba02d934ca5fdfdc7dd

commit 24a8ad434aab59c8c8a08ba02d934ca5fdfdc7dd
Author: jzfeng <jzfeng@chromium.org>
Date: Sat Apr 08 02:30:10 2017

add a new set of commands to resize and position windows

https://docs.google.com/a/google.com/document/d/1iDSRQzYiF6xYKp2PuA8kBmghK7Ar0OZXQZFsaUBNgKw/edit?usp=sharing

Devtools side, add a new UI domain and methods:
method: getWindowForTarget, param: targetID, return: windowID, bounds.
method: setWindowBounds, param: windowID, bounds
method: getWindowBounds, param: windowID, return: bounds

bounds object: left, top, width, height, window_state (minimized, maximized, fullscreen, normal)

BUG=604324

Review-Url: https://codereview.chromium.org/2734123004
Cr-Commit-Position: refs/heads/master@{#463110}

[modify] https://crrev.com/24a8ad434aab59c8c8a08ba02d934ca5fdfdc7dd/chrome/browser/devtools/chrome_devtools_manager_delegate.cc
[modify] https://crrev.com/24a8ad434aab59c8c8a08ba02d934ca5fdfdc7dd/chrome/browser/devtools/chrome_devtools_manager_delegate.h
[modify] https://crrev.com/24a8ad434aab59c8c8a08ba02d934ca5fdfdc7dd/chrome/browser/devtools/devtools_protocol.cc
[modify] https://crrev.com/24a8ad434aab59c8c8a08ba02d934ca5fdfdc7dd/chrome/browser/devtools/devtools_protocol.h
[modify] https://crrev.com/24a8ad434aab59c8c8a08ba02d934ca5fdfdc7dd/chrome/browser/devtools/devtools_sanity_browsertest.cc
[modify] https://crrev.com/24a8ad434aab59c8c8a08ba02d934ca5fdfdc7dd/third_party/WebKit/LayoutTests/inspector/schema-get-domains-matches-agents-expected.txt
[modify] https://crrev.com/24a8ad434aab59c8c8a08ba02d934ca5fdfdc7dd/third_party/WebKit/Source/core/inspector/browser_protocol.json

Make a copy of the doc: Migrate chromedriver extension to devtool commands
https://docs.google.com/document/d/1Q0kuHgU1d-sj8gePjEU9nHtlQzz5rNvvGH8fCJ3iBq4/edit?usp=sharing.

This version is shared to public.
Project Member Comment 26 by bugdroid1@chromium.org, Apr 10
The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/da1d85c561f4c7b666dfc1ae5acb3310d9b78a20

commit da1d85c561f4c7b666dfc1ae5acb3310d9b78a20
Author: jzfeng <jzfeng@chromium.org>
Date: Mon Apr 10 20:54:36 2017

Revert of add a new set of commands to resize and position windows (patchset #35 id:680001 of https://codereview.chromium.org/2734123004/ )

Reason for revert:
It cause flaky browser tests on mac10.10

https://uberchromegw.corp.google.com/i/chromium.mac/builders/Mac10.10%20Tests?numbuilds=100

Original issue's description:
> add a new set of commands to resize and position windows
>
> https://docs.google.com/document/d/1Q0kuHgU1d-sj8gePjEU9nHtlQzz5rNvvGH8fCJ3iBq4/edit?usp=sharing
>
> Devtools side, add a new UI domain and methods:
> method: getWindowForTarget, param: targetID, return: windowID, bounds.
> method: setWindowBounds, param: windowID, bounds
> method: getWindowBounds, param: windowID, return: bounds
>
> bounds object: left, top, width, height, window_state (minimized, maximized, fullscreen, normal)
>
> BUG=604324
>
> Review-Url: https://codereview.chromium.org/2734123004
> Cr-Commit-Position: refs/heads/master@{#463110}
> Committed: https://chromium.googlesource.com/chromium/src/+/24a8ad434aab59c8c8a08ba02d934ca5fdfdc7dd

TBR=dgozman@chromium.org,pfeldman@chromium.org,samuong@chromium.org

Review-Url: https://codereview.chromium.org/2808923002
Cr-Commit-Position: refs/heads/master@{#463388}

[modify] https://crrev.com/da1d85c561f4c7b666dfc1ae5acb3310d9b78a20/chrome/browser/devtools/chrome_devtools_manager_delegate.cc
[modify] https://crrev.com/da1d85c561f4c7b666dfc1ae5acb3310d9b78a20/chrome/browser/devtools/chrome_devtools_manager_delegate.h
[modify] https://crrev.com/da1d85c561f4c7b666dfc1ae5acb3310d9b78a20/chrome/browser/devtools/devtools_protocol.cc
[modify] https://crrev.com/da1d85c561f4c7b666dfc1ae5acb3310d9b78a20/chrome/browser/devtools/devtools_protocol.h
[modify] https://crrev.com/da1d85c561f4c7b666dfc1ae5acb3310d9b78a20/chrome/browser/devtools/devtools_sanity_browsertest.cc
[modify] https://crrev.com/da1d85c561f4c7b666dfc1ae5acb3310d9b78a20/third_party/WebKit/LayoutTests/inspector/schema-get-domains-matches-agents-expected.txt
[modify] https://crrev.com/da1d85c561f4c7b666dfc1ae5acb3310d9b78a20/third_party/WebKit/Source/core/inspector/browser_protocol.json

Project Member Comment 27 by bugdroid1@chromium.org, Apr 13
The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/dd0fef609820bee5b4e9b6aa46dd4ee3dd53f81f

commit dd0fef609820bee5b4e9b6aa46dd4ee3dd53f81f
Author: jzfeng <jzfeng@chromium.org>
Date: Thu Apr 13 02:59:17 2017

Add a new set of commands to resize and position windows

https://docs.google.com/document/d/1Q0kuHgU1d-sj8gePjEU9nHtlQzz5rNvvGH8fCJ3iBq4/edit?usp=sharing

Devtools side, add a new UI domain and methods:
method: getWindowForTarget, param: targetID, return: windowID, bounds.
method: setWindowBounds, param: windowID, bounds
method: getWindowBounds, param: windowID, return: bounds

bounds object: left, top, width, height, window_state (minimized, maximized, fullscreen, normal)

BUG=604324

Review-Url: https://codereview.chromium.org/2813553005
Cr-Commit-Position: refs/heads/master@{#464265}

[modify] https://crrev.com/dd0fef609820bee5b4e9b6aa46dd4ee3dd53f81f/chrome/browser/devtools/chrome_devtools_manager_delegate.cc
[modify] https://crrev.com/dd0fef609820bee5b4e9b6aa46dd4ee3dd53f81f/chrome/browser/devtools/chrome_devtools_manager_delegate.h
[modify] https://crrev.com/dd0fef609820bee5b4e9b6aa46dd4ee3dd53f81f/chrome/browser/devtools/devtools_protocol.cc
[modify] https://crrev.com/dd0fef609820bee5b4e9b6aa46dd4ee3dd53f81f/chrome/browser/devtools/devtools_protocol.h
[add] https://crrev.com/dd0fef609820bee5b4e9b6aa46dd4ee3dd53f81f/chrome/browser/devtools/devtools_sanity_interactive_browsertest.cc
[modify] https://crrev.com/dd0fef609820bee5b4e9b6aa46dd4ee3dd53f81f/chrome/test/BUILD.gn
[modify] https://crrev.com/dd0fef609820bee5b4e9b6aa46dd4ee3dd53f81f/third_party/WebKit/LayoutTests/inspector/schema-get-domains-matches-agents-expected.txt
[modify] https://crrev.com/dd0fef609820bee5b4e9b6aa46dd4ee3dd53f81f/third_party/WebKit/Source/core/inspector/browser_protocol.json

Blockedon: chromedriver:1772
I think it would be best to allow configuration of security settings (preferably via CLI arguments) when running in headless mode, just like when in normal mode.

For example, --allow-running-insecure-content and --ignore-certificate-errors work in normal mode but seem to be quietly ignored when running headless.

My use case consists of controlling Chromium via Selenium for the purpose of performing security tests against web applications[1] and now that PhantomJS is going and Chromium got a headless mode, Chromium is the best migration choice.
However, such a system needs to be resilient and forgiving, like most browsers, and support a wide range of web applications, but the fact that headless is currently imposing unconfigurable restrictions that prevent pages from even loading is making the situation unworkable.

Also, it would be a good idea to exit with a message when a given option is not supported in headless mode to avoid confusion.

[1] http://www.arachni-scanner.com/
#30: We've added new commands for overriding certificate handling -- see https://chromedevtools.github.io/debugger-protocol-viewer/tot/Security/#method-handleCertificateError

In general I think new DevTools commands are preferable over command line flags because they offer the most flexibility.
#31: If I can make that work from a Selenium/Chromedriver perspective then I'm a happy camper, although I don't see how yet.

Also, is there any chance that more security related options can be added to the API to enable loading insecure content, disable XSS protection and the rest?
#32: Definitely, if you feel like something is missing please file bugs with descriptions of your use case.
Components: Internals>Headless
Project Member Comment 35 by bugdroid1@chromium.org, May 25
The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/cbecd589a9ca1e66959de5bc3b6016ff1adb5d21

commit cbecd589a9ca1e66959de5bc3b6016ff1adb5d21
Author: jzfeng <jzfeng@chromium.org>
Date: Thu May 25 07:40:34 2017

Implement window management devtools commands for headless.

These commands are used by chromedriver to change window bounds (size, position) and state (normal, minimized, maximized, fullscreen).

1. add window state to HeadlessWebContentsImpl to track window states change.
2. add window id to HeadlessWebContentsImpl as an unique id used by the commands.
3. window size doesn't change when its state changes.

BUG=604324

Review-Url: https://codereview.chromium.org/2896763002
Cr-Commit-Position: refs/heads/master@{#474601}

[modify] https://crrev.com/cbecd589a9ca1e66959de5bc3b6016ff1adb5d21/headless/BUILD.gn
[modify] https://crrev.com/cbecd589a9ca1e66959de5bc3b6016ff1adb5d21/headless/lib/browser/headless_browser_impl.cc
[modify] https://crrev.com/cbecd589a9ca1e66959de5bc3b6016ff1adb5d21/headless/lib/browser/headless_browser_impl.h
[modify] https://crrev.com/cbecd589a9ca1e66959de5bc3b6016ff1adb5d21/headless/lib/browser/headless_devtools_client_impl.cc
[modify] https://crrev.com/cbecd589a9ca1e66959de5bc3b6016ff1adb5d21/headless/lib/browser/headless_devtools_client_impl.h
[modify] https://crrev.com/cbecd589a9ca1e66959de5bc3b6016ff1adb5d21/headless/lib/browser/headless_devtools_manager_delegate.cc
[modify] https://crrev.com/cbecd589a9ca1e66959de5bc3b6016ff1adb5d21/headless/lib/browser/headless_devtools_manager_delegate.h
[modify] https://crrev.com/cbecd589a9ca1e66959de5bc3b6016ff1adb5d21/headless/lib/browser/headless_web_contents_impl.cc
[modify] https://crrev.com/cbecd589a9ca1e66959de5bc3b6016ff1adb5d21/headless/lib/browser/headless_web_contents_impl.h
[modify] https://crrev.com/cbecd589a9ca1e66959de5bc3b6016ff1adb5d21/headless/lib/headless_devtools_client_browsertest.cc
[modify] https://crrev.com/cbecd589a9ca1e66959de5bc3b6016ff1adb5d21/headless/public/headless_devtools_client.h
[modify] https://crrev.com/cbecd589a9ca1e66959de5bc3b6016ff1adb5d21/headless/test/headless_browser_test.cc
[modify] https://crrev.com/cbecd589a9ca1e66959de5bc3b6016ff1adb5d21/headless/test/headless_browser_test.h

Comment 37 by ericbidelman@chromium.org, Jun 22 (4 days ago)
Cc: ericbidelman@chromium.org
Comment 38 by ericbidelman@chromium.org, Jun 22 (4 days ago)
It looks like screenshots also do not work. This returns 1x1px screenshot (chromedriver 2.30.1, on Mac):

const fs = require('fs');
const webdriver = require('selenium-webdriver');
const chromedriver = require('chromedriver');

const chromeCapabilities = webdriver.Capabilities.chrome();
chromeCapabilities.set('chromeOptions', {
  'args': [
    '--headless',
    '--disable-gpu',
    // '--window-size=412,732'
  ]
});

const driver = new webdriver.Builder()
  .forBrowser('chrome')
  .withCapabilities(chromeCapabilities)
  .build();

// driver.manage().window().setSize(412, 732);
driver.get('https://www.google.com/');
driver.takeScreenshot().then(base64png => {
  const buffer = new Buffer(base64png, 'base64');
  fs.writeFileSync('screenshot.png', buffer);
});
driver.quit();
Sign in to add a comment