karma: Karma 1.6 breaks Headless support for Chrome
Expected behaviour
When using Karma 1.6, you should be able to use chrome headless support
Actual behaviour
Chrome won’t start with headless mode
> karma start --single-run --browsers=Chrome_Beta_Headless
07 04 2017 15:21:17.494:WARN [watcher]: All files matched by "/opt/atlassian/pipelines/agent/build/packages/sams-client/dist/_test/_setup/main.js" were excluded or matched by prior matchers.
07 04 2017 15:21:18.853:INFO [karma]: Karma v1.6.0 server started at http://0.0.0.0:9876/
07 04 2017 15:21:18.854:INFO [launcher]: Launching browser Chrome_Beta_Headless with unlimited concurrency
07 04 2017 15:21:18.863:INFO [launcher]: Starting browser Chrome
07 04 2017 15:21:19.403:INFO [HeadlessChrome 0.0.0 (Linux 0.0.0)]: Connected on socket NKuNZ76kZe8lL7FnAAAA with id 75816684
07 04 2017 15:21:29.405:WARN [HeadlessChrome 0.0.0 (Linux 0.0.0)]: Disconnected (1 times), because no message in 10000 ms.
HeadlessChrome 0.0.0 (Linux 0.0.0) ERROR
Disconnected, because no message in 10000 ms.
Environment Details
- Karma version (output of
karma --version): 1.6 - Relevant part of your
karma.config.jsfile
browsers: ["Chrome", "Chrome_Beta_Headless"],
customLaunchers: {
Chrome_Beta_Headless: {
base: 'Chrome',
flags: ['--headless', '--disable-gpu', '--remote-debugging-port=9222']
}
},
Steps to reproduce the behaviour
- Setup a custom launcher as above
- karma start --single-run --browsers=Chrome_Beta_Headless
- Get the error above.
- Rollback to Karma 1.5, everything works.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 28
- Comments: 97 (12 by maintainers)
Commits related to this issue
- fix(tests): workaround for resolving Karma timeout issues on Windows (cf. https://github.com/karma-runner/karma-chrome-launcher/issues/154, https://github.com/karma-runner/karma/issues/2652) — committed to oblique-bit/oblique by almeidap 6 years ago
- Merge pull request #15 in OUI/oblique2-reactive from v6 to develop * commit 'ac7fe35e7938c8735f9589a75713174eb42e5683': chore: move build options to angular.json fix(tests): workaround for resolv... — committed to oblique-bit/oblique by almeidap 6 years ago
Well I think I found what was causing the issue for me. In my case I noticed that there was a connection that was disconnecting too soon.
I found that in /static/karma.js, when the socket is created, there is a
timeoutvalue that is hardcoded to 2 seconds (see below). I just added another 0 to make it 20 seconds and the connection stayed open long enough for the server to respond to the initial request. https://github.com/karma-runner/karma/blob/e79463b94ff6d3ad87526b3c68b38b90e924ea42/client/main.js#L14-L20The next problem I faced was that Karma thought there was no activity even though there was traffic going back and forth on the socket. To fix that I just added
browserNoActivityTimeout: 60000to the Karma configuration.Is there anyway the socket timeout can be configurable?
Got into this with karma
v1.7.0Google Chrome 59.0.3071.86karma --version): 1.7karma.config.jsfileI am seeing this on both Windows (7,10) and Linux in Karma v2 and v1.7.1. A google search suggests that this has been an outstanding issue for quite some time, would be great to get a definitive fix.
Still happening with Angular v6 and cli v6.0.
I got exactly same error as @mskutin with same versions of Karma and Chrome. Can’t reproduce it on OS X or Docker container running in Docker for Mac. Although happens every time in Docker container running on build server (Cent OS 7.3).
Investigation showed that it is related to the slower machine and happens, because it took >10 seconds before test bundle was parsed and executed by Chrome and therefore test run was started and communicated back to Karma server. Reasons why it may take long vary.
There are 2 ways to handle timeout:
browserNoActivityTimeoutto highter value, so test bundle has enough time to load.This particular appearance of timeout does not seem to be a Karma issue, but rather problem in the project or misconfiguration.
I’m wondering, is there any maintainer on this project?
This issue filed almost year ago, and now it is second top commented issue in the project.
The reason of the issue was already found by @daryl0313 six months ago.
People cannot use headless chrome through karma because of this.
What’s the problem to fix it? Any response from maintainer/contributors would be good.
@daryl0313 that fixed it for me. But someone should examine, why it takes so long to connect instead of just checking in a work-around
same for me
Chrome v61,karma v1.7.1(andv1.5.0),windows 7not sure if this is right place to complain, since i’ve tried karma
v1.5.0which did not work for me either.confused whether reason is
chromeversion orkarmaversion orosversion or certain combination of them…This might not add much value to the conversation but I’ll post my workaround anyways.
My use case is testing an Angular app. Karma 2.0.0 + karma-chrome-launcher 2.2.0, and running the tests on headless chrome. I installed karma-spec-reporter to see what test was causing the crash and it turned out that there was a test calling the
saveAsmethod from the packagefile-saver, thus trying to download file on test execution. (I know, noob mistake). So I added a spy to thesaveAsmethod and just stubbed the call. Problem solved.Tried all the above suggestions. None worked for me. The test runner times out without executing any tests on
chrome headlessonUbuntu Server 14.04.5 LTS.Why does this happen? Any workaround? Note: The tests run perfectly on myOSXmachine [Sierra] withkarma,karma-chrome-launcher, with headless chrome setup. The problem is just on the linux server.Error:
Here is my configuration:
I have logged an issue on karma-chrome-launcher repo here
Using @swetapatil1 answer, I am now able to finally work!
Using the flags from this:
I was finally able to forge a working karma.conf.json (for headless ubuntu+chrome):
karma.conf.json
@Chido42 disabling VirtualBox network adapters fixed it IMMEDIATELY for me. Thanks so much. Two days of digging on this. You’re the best!
I’ve been having this issue with karma 2 with angular-cli, downgrading to 1.7.1 solved this for me
This issue is quite annoying. I’ve wasted a few hours trying to poke around it, but testing in Chrome just will not work. The only solution for us was to use Firefox in our Docker image - worked without any issues at all. We didn’t even have to set
browserNoActivityTimeout- it connected right after our angular application was built.To anybody who might be having this issue - if it’s not of absolute must for you to be using Chrome - safe your time on a wasted cause. Apparently this issue needs more attention from the contributors/owners!
Ping @maksimr, @devoto13 anybody else ?
@artin-phares Well, I feel the solution proposed by @daryl0313 was more a workaround than a permanent fix. Nobody still nailed the issue.
I’m also concern about the lack of response of any maintainer/contributor. As I said, we could have made a PR long time ago with the proposed workaround, but I doubt anybody would have merged it since the issue probably lies somewhere else.
Still, someone more involved in Karma DEV should have a look at this. That being said, I didn’t have a chance of trying it with the Karma 2.x version, wonder if it fixes anything, I know they updated a lot of deps and the issue seems to came from SocketIO somehow…
After a long investigation the error was due to having Virtualbox installed with the VirtualBox Host-Only Network interface enabled.
Once this network interface disabled no more issue. From our investigation it seems this interface slows down the connection a lot and since the timeout to connect it hardcoded inside the lib it fails to connect.
While changing the hardcoded timeout value (by a huge number) it also solved the issue. Not sure if an issue should be also opened to virtualbox.
@bas-l @MikaAK That’s weird seems like 2.0.0 + karma-chrome-launcher 2.2.0 solve it for me.
@applecool
Just managed to get puppeteer to work, inside a docker container.
Just note that, if using docker, you must run
npm installin the container.If not running docker, make sure your host got all the libraries installed.
Here are the relevant bits:
package.json
karma.conf.js:
Dockerfile
Not working for me.
Using latest karma, latest karma chrome runner, latest jasmine and latest Chrome.
Headless mode does not work. Same ‘disconnected’ issues as everyone else is having.
For me it does work again after downgrading to karma 1.5.
I’m having to run it in this docker:
Which times out karma 1.6 but works fine with karma 1.5. Fully reproducible.
Setting
browserNoActivityTimeout: 60000helped us solve a whole class of problems. We run our stuff in a Docker container (both Chrome headless and the tests themselves live in the same container).Is virtualization or containerization contributing to this issue at all?
Installation of karma-cli resolved that issue for me
@daryl0313 It’s not necessary to define your own launcher.
karma-firefox-launchermakes theFirefoxHeadlesslauncher available so you may just use it. If it doesn’t work for you then you may have an older version of the package; just updatekarma-firefox-launcherand it’ll be fine.I’ve found also that when we upgraded build machine for tests to 4 cores, 16GB of RAM and SSD disk, problem disappeared. I assume that karma has some timeouts that breaks on slower machines. Maybe this is just a lucky, I don’t know. We just upgraded Azure machine…
I think, that is stopped being funny a while ago. Same issues on Ubuntu, trying now with changes both timeouts.
I’m using Karma version 1.4.1 and I also having this behavior on windows. First run works, but when I start it a second time it would fail. If I close the console and reopen it then it works (but again only for the first time, second call breaks again).
You can look at CHANGELOG.
Did you try run sample project on Bitbucket? Is it reproduced locally? Does it work if downgrade on karma@1.5.x?