question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

chrome-launcher does not work on docker ubuntu (even with xvfb-run)

See original GitHub issue

The problem: Running karma + karma-chrome-launcher on ubuntu docker container does not work

Steps tried:

Anyone have other ideas?

Example tiny project with docker container. This repo contains a replicable error:

root@e69e39f2f599:/karma# xvfb-run npm test

> @ test /karma
> ./node_modules/karma/bin/karma start karma.conf.js --single-run --log-level debug

22 11 2016 17:20:02.713:DEBUG [config]: Loading config /karma/karma.conf.js
22 11 2016 17:20:02.720:DEBUG [config]: autoWatch set to false, because of singleRun
22 11 2016 17:20:02.722:DEBUG [plugin]: Loading karma-* from /karma/node_modules
22 11 2016 17:20:02.724:DEBUG [plugin]: Loading plugin /karma/node_modules/karma-chrome-launcher.
22 11 2016 17:20:02.745:DEBUG [plugin]: Loading plugin /karma/node_modules/karma-jasmine.
22 11 2016 17:20:02.747:DEBUG [plugin]: Loading inlined plugin (defining launcher:my_chrome).
22 11 2016 17:20:02.757:DEBUG [web-server]: Instantiating middleware
22 11 2016 17:20:02.818:INFO [karma]: Karma v1.3.0 server started at http://localhost:9876/
22 11 2016 17:20:02.819:INFO [launcher]: Launching browser my_chrome with unlimited concurrency
22 11 2016 17:20:02.828:INFO [launcher]: Starting browser Chrome
22 11 2016 17:20:02.829:DEBUG [temp-dir]: Creating temp dir at /karma/karma-95080039
22 11 2016 17:20:02.831:DEBUG [launcher]: google-chrome --user-data-dir=/karma/karma-95080039 --no-default-browser-check --no-first-run --disable-default-apps --disable-popup-blocking --disable-translate --disable-background-timer-throttling --disable-device-discovery-notifications --disable-gpu --no-sandbox http://localhost:9876/?id=95080039
22 11 2016 17:20:03.011:DEBUG [launcher]: Process Chrome exited with code 0
22 11 2016 17:20:03.011:ERROR [launcher]: Cannot start Chrome

22 11 2016 17:20:03.012:DEBUG [temp-dir]: Cleaning temp dir /karma/karma-95080039
22 11 2016 17:20:03.016:INFO [launcher]: Trying to start Chrome again (1/2).
22 11 2016 17:20:03.017:DEBUG [launcher]: Restarting Chrome
22 11 2016 17:20:03.017:DEBUG [temp-dir]: Creating temp dir at /karma/karma-95080039
22 11 2016 17:20:03.018:DEBUG [launcher]: google-chrome --user-data-dir=/karma/karma-95080039 --no-default-browser-check --no-first-run --disable-default-apps --disable-popup-blocking --disable-translate --disable-background-timer-throttling --disable-device-discovery-notifications --disable-gpu --no-sandbox http://localhost:9876/?id=95080039
22 11 2016 17:20:03.174:DEBUG [launcher]: Process Chrome exited with code 0
22 11 2016 17:20:03.175:ERROR [launcher]: Cannot start Chrome

22 11 2016 17:20:03.175:DEBUG [temp-dir]: Cleaning temp dir /karma/karma-95080039
22 11 2016 17:20:03.178:INFO [launcher]: Trying to start Chrome again (2/2).
22 11 2016 17:20:03.179:DEBUG [launcher]: Restarting Chrome
22 11 2016 17:20:03.180:DEBUG [temp-dir]: Creating temp dir at /karma/karma-95080039
22 11 2016 17:20:03.181:DEBUG [launcher]: google-chrome --user-data-dir=/karma/karma-95080039 --no-default-browser-check --no-first-run --disable-default-apps --disable-popup-blocking --disable-translate --disable-background-timer-throttling --disable-device-discovery-notifications --disable-gpu --no-sandbox http://localhost:9876/?id=95080039
22 11 2016 17:20:03.342:DEBUG [launcher]: Process Chrome exited with code 0
22 11 2016 17:20:03.343:ERROR [launcher]: Cannot start Chrome

22 11 2016 17:20:03.344:DEBUG [temp-dir]: Cleaning temp dir /karma/karma-95080039
22 11 2016 17:20:03.346:ERROR [launcher]: Chrome failed 2 times (cannot start). Giving up.
22 11 2016 17:20:03.347:DEBUG [karma]: Run complete, exiting.
22 11 2016 17:20:03.347:DEBUG [launcher]: Disconnecting all browsers
npm ERR! Test failed.  See above for more details.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:10
  • Comments:9

github_iconTop GitHub Comments

8reactions
myitcvcommented, Feb 16, 2017

Replying to self… I’ve still not managed to track down what’s going wrong here… despite resorting to strace to try and see where things are hanging within the Chrome process.

But I have found a (temporary) solution, an alternative to the approach @jadekler describes above (which we needed because @jadekler’s solution did not work for us)

This solution works for us with Google Chrome 57.0.2987.54 beta

It involves defining a custom launcher and taking advantage of Chrome’s new --headless flag:

// karma.conf.js

// ...

  browsers: ['OurChrome'],
  customLaunchers: {
    OurChrome: {
      base: 'Chrome',
      flags: ['--headless', '--disable-gpu', '--remote-debugging-port=9222']
    }
  },

// ...

At this point I also note https://github.com/karma-runner/karma/issues/2489

@dignifiedquire is it worth trying to debug further with the strace output I have? Or is https://github.com/karma-runner/karma/issues/2489 really the best way forward here?

4reactions
aincommented, May 26, 2017

Could anyone please explain why was this ticket closed?

With the latest karma-chrome-launcher it still isn’t working out of the box on GitLab CI, incl. with the @myitcv’s suggestion above.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Xvfb & Docker - display suddenly stops working - Stack Overflow
I need to run XVFB in a docker container in order to make a puppeteer web scraper work in headful mode. Here is...
Read more >
How to use Puppeteer inside a Docker container
now i am trying to dockerize it and it get's deployed but throws the following error. "Failed to launch the browser process! spawn...
Read more >
Window does not get maximized in docker container
Hello, Has anyone noticed that maximizeWindow() keyword does not work in docker container. I have checked the screenshots after the tests ...
Read more >
Getting Started with Headless Chrome - Chrome Developers
The easiest way to get started with headless mode is to open the Chrome ... In some cases, you may not need to...
Read more >
Headfull browsers beat headless | Pierce Freeman
Twenty years ago a simple curl would open up the world. ... Extensions are one example; Chrome supports them but headless does not....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found