docker-selenium icon indicating copy to clipboard operation
docker-selenium copied to clipboard

node-chrome with --headless rather than XVFB

Open graingert opened this issue 9 years ago • 73 comments

Run node-chrome with --headless rather than XVFB, to reduce resource usage.

graingert avatar Mar 30 '17 17:03 graingert

Users don't browse in xvfb, what's your point?

graingert avatar Apr 11 '17 21:04 graingert

no, users use the physical browser. Xvfb allows the rendering of said physical browsers.

ddavison avatar Apr 12 '17 01:04 ddavison

Are you suggesting that chrome --headless behaves differently from chrome under xvfb?

On 12 Apr 2017 02:29, "Dj" [email protected] wrote:

no, users use the physical browser. Xvfb allows the rendering of said physical browsers.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/SeleniumHQ/docker-selenium/issues/429#issuecomment-293446550, or mute the thread https://github.com/notifications/unsubscribe-auth/AAZQTMWyJFMfal-UsVak1INjMBFNCeS7ks5rvCkKgaJpZM4MusZ3 .

graingert avatar Apr 12 '17 01:04 graingert

PhantomJS' solo maintainer is leaving because of headless chrome. Can we reopen this discussion? (source: https://groups.google.com/forum/#!topic/phantomjs/9aI5d-LDuNE)

SpencerMalone avatar Apr 13 '17 16:04 SpencerMalone

i guess i'm not familiar with chrome's headless mode.. tell me more, @graingert

ddavison avatar Apr 13 '17 16:04 ddavison

@ddavison you run chrome --headless and it manages its own internal framebuffer, rather than needing X11

It should massively simplify the default node-chrome.

Also it's got a VNC like protocol over the chrome debug socket, so you wouldn't need node-chrome-debug either

graingert avatar Apr 13 '17 16:04 graingert

I think the biggest benefit that users find with the debug, is that you can VNC into it. You're saying that this could be eliminated? If that's the case, ok then. sign me up - apologies for the abrupt closing. An issue file with a very small description is dangerous as it leaves everything up to speculation :)

I wasn't familiar with chrome --headless (hence why i asked you to elaborate)

If this is possible, then yes.. we'll go this route. I'll keep this issue open and i'll mark as investigating.

ddavison avatar Apr 13 '17 16:04 ddavison

I think most automated testing will use chrome headless going forwards, and using docker for automated testing is a perfect fit, so this just seems like an obvious thing, in fact, iv been asking about it for the last few months and even tried to roll my own but chrome --headless was buggy. Big +1 from me on this as PhantomJS 2.5 release isn't even available and maybe we won't see it now that the maintainer has stepped down.

The main reason is quite simple.... Chrome uses a lot of memory and cpu and that should be lower without Xvfb and real rendering.

madhavajay avatar Apr 18 '17 07:04 madhavajay

So, I just put in some time into this. XVFB will still be required for almost all projects, sadly (unless someone finds a workaround)

In general it wasn't too rough to get running, but I get thrown the following when I try to use it for tests that have keyCode interactions (aka, any sendkeys stuff):

unknown error: an X display is required for keycode conversions, consider using Xvfb
        (Session info: content shell=)
        (Driver info: chromedriver=2.29.461571 (8a88bbe0775e2a23afda0ceaf2ef7ee74e822cc5),platform=Linux 4.9.4-moby x86_64) (WARNING: The server did not provide any stacktrace information)
      Command duration or timeout: 26 milliseconds
      Build info: version: '2.52.0', revision: '4c2593c', time: '2016-02-11 19:06:42'
      System info: host: '1d5acd9906ce', ip: '172.17.0.4', os.name: 'Linux', os.arch: 'amd64', os.version: '4.9.4-moby', java.version: '1.8.0_121'
      Driver info: org.openqa.selenium.chrome.ChromeDriver

EDIT: Throwing XVFB in and using that to run the SE process (like normal), it all works properly, I'm just not sure that we're gaining much if we do that.

I haven't poked around with this repo in ages. Do y'all have a standardish way of measuring performance?

SpencerMalone avatar Apr 19 '17 16:04 SpencerMalone

I guess the XVFB thing is a chromedriver requirement, so I opened a ticket here: https://bugs.chromium.org/p/chromedriver/issues/detail?id=1772

If you wanna reproduce / help out with finding a fix, you can find steps to make an easy one-off container that runs selenium locally (without a hub/node configuration) in that issue. It's easy enough to convert those steps into the docker-selenium containers, but the send key stuff still exists.

SpencerMalone avatar Apr 19 '17 17:04 SpencerMalone

Indeed, I managed even to set the Chrome browser window size but once I removed Xvfb from docker-selenium I was also bitten by @SpencerMalone error:

Failed: unknown error: an X display is required for keycode conversions, consider using Xvfb
  (Session info: headless chrome=58.0.3029.81)
  (Driver info: chromedriver=2.29.461571 (8a88bbe0775e2a23afda0ceaf2ef7ee74e822cc5),platform=Linux 4.4.0-72-generic x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 22 milliseconds
Build info: version: '3.3.1', revision: '5234b32', time: '2017-03-10 09:04:52 -0800'
System info: host: 'ccd8e5f77172', ip: '172.17.0.2', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-72-generic', java.version: '1.8.0_121'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.29.461571 (8a88bbe0775e2a23afda0ceaf2ef7ee74e822cc5), userDataDir=/tmp/.org.chromium.Chromium.u1tWQG}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=58.0.3029.81, platform=LINUX, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=}]
Session ID: a7bc6bb38644f13e7a9c9b2c33fbcd61

elgalu avatar Apr 21 '17 12:04 elgalu

I like the idea but please do not remove the current node-chrome and node-chrome-debug images when creating the headless images. I still like the idea of using real browsers inside containers.

testphreak avatar Apr 21 '17 16:04 testphreak

I think there won't be need to remove them, or even create a new image, you just need to pass some specific capabilities to Chrome, I think @elgalu showed them to me yesterday, can you share them?

diemol avatar Apr 22 '17 06:04 diemol

Correct, this works already:

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

elgalu avatar Apr 22 '17 14:04 elgalu

Using the selenium node base image, I've found the following configuration works best:

capabilities: {
    browserName: 'chrome',
    chromeOptions: {
        args: ['headless','no-sandbox','disable-gpu','window-size=1920x1080']
    }
}

Keeping the sandbox enabled caused an exception when selenium tried to start chrome.

I put together an example app that extends the selenium node base image, installs latest snapshot of chromium (with headless bugfixes), and installs a recent build of chromedriver which allows chrome > 59. Unfortunately, I also discovered xvfb is required for sendKeys to work.

erithmetic avatar Apr 22 '17 15:04 erithmetic

Would be good to have a separate image node-chrome-headless to save space on xvfb and deps

On 22 Apr 2017 16:10, "Derek Kastner" [email protected] wrote:

Using the selenium node base image, I've found the following configuration works best:

capabilities: { browserName: 'chrome', chromeOptions: { args: ['headless','no-sandbox','disable-gpu','window-size=1920x1080'] } }

Keeping the sandbox enabled caused an exception when selenium tried to start chrome.

I put together an example app https://github.com/dkastner/headless-chromium-selenium that extends the selenium node base image, installs latest snapshot of chromium (with headless bugfixes), and installs a recent build of chromedriver which allows chrome > 59. Unfortunately, I also discovered xvfb is required for sendKeys to work.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/SeleniumHQ/docker-selenium/issues/429#issuecomment-296379624, or mute the thread https://github.com/notifications/unsubscribe-auth/AAZQTF5zuwN0IBMsL9Bq1m1B9eulvid5ks5ryhhOgaJpZM4MusZ3 .

graingert avatar Apr 22 '17 18:04 graingert

Awesome! This sounds like it requires half the resources of selenium/standalone-chrome (e.g. disk, RAM)

alippai avatar May 03 '17 15:05 alippai

yes, which would be super useful as we're hitting the resource limits on our aws instances using the standard selenium images. Headless should help there.

ghost avatar May 24 '17 03:05 ghost

@graingert, is it possible already to run Chrome headless without xvfb?

diemol avatar May 28 '17 17:05 diemol

Yes

On 28 May 2017 18:31, "Diego Molina" [email protected] wrote:

@graingert https://github.com/graingert, is it possible already to run Chrome headless without xvfb?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/SeleniumHQ/docker-selenium/issues/429#issuecomment-304528556, or mute the thread https://github.com/notifications/unsubscribe-auth/AAZQTGeJl_QBzx8dASjI8P2XPBjTHTWYks5r-a-CgaJpZM4MusZ3 .

graingert avatar May 28 '17 17:05 graingert