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.

Headless Chrome times out without executing any tests

See original GitHub issue

I have configured the headless chrome in my project getting rid of Phantom. When I run the tests on my OSX machine, all the tests get executed with the test runner on the headless chrome. But the same doesn’t happen on my linux server. It connects to the socket and then after some time, it disconnects and shows the error message saying “Karma tests failed”. Error:

25 09 2017 13:56:19.075:INFO [karma]: Karma v1.5.0 server started at http://0.0.0.0:9876/build/
25 09 2017 13:56:19.076:INFO [launcher]: Launching browser ChromeHeadless with unlimited concurrency
25 09 2017 13:56:19.080:INFO [launcher]: Starting browser Chrome
25 09 2017 13:56:19.263:INFO [HeadlessChrome 0.0.0 (Linux 0.0.0)]: Connected on socket zDM7md2A7Je8kqsPAAAA with id 1679961
25 09 2017 13:58:19.552:WARN [HeadlessChrome 0.0.0 (Linux 0.0.0)]: Disconnected (1 times), because no message in 120000 ms.
HeadlessChrome 0.0.0 (Linux 0.0.0) ERROR
  Disconnected, because no message in 120000 ms.

Here is my configuration:

const ChromiumRevision = require('puppeteer/package.json').puppeteer.chromium_revision;
const Downloader = require('puppeteer/utils/ChromiumDownloader');
const revisionInfo = Downloader.revisionInfo(Downloader.currentPlatform(), ChromiumRevision);

process.env.CHROME_BIN = revisionInfo.executablePath;
module.exports = function (config) {
    config.set({
        basePath: 'build/',
        frameworks: ['jasmine'],
        plugins: [
            require('karma-jasmine'),
            require('karma-chrome-launcher'),
        ],
        files: ['tests.js'],
        customLaunchers: {
            'ChromeHeadless': {
                base: 'Chrome',
                flags: [
                    '--headless',
                    '--disable-gpu',
                    // Without a remote debugging port, Google Chrome exits immediately.
                    '--remote-debugging-port=9222'
                ],
                debug: true
            }
        },
        autoWatch: false,
        browsers: ['ChromeHeadless'],
        singleRun: true,
        browserNoActivityTimeout: 120000,
        urlRoot: '/build/'
    })
}

Using karma-chrome-launcher: "2.1.1". Tried with the latest 2.2.0 version too. Tried with karma: "1.5.0", "1.6.0", and the latest "1.7.1".

I tried other flags like “--no-sandbox”, “--disable-web-security” as suggested on a bunch of issues on karma repo. But still no luck. Is there a fix or workaround for this issue? Is there a reason why it’s not working on the Linux server [Ubuntu Server 14.04.5 LTS].

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:97
  • Comments:132 (2 by maintainers)

github_iconTop GitHub Comments

75reactions
ghostcommented, Oct 3, 2017

try npm install && npm rebuild && npm test This worked for me

Also adding --no-sandbox to the flag list helps

64reactions
andrewl-telnyxcommented, Oct 5, 2017

npm install && npm rebuild && npm test

const process = require('process');
process.env.CHROME_BIN = require('puppeteer').executablePath();

//later:
 browsers: ['HeadlessChrome'],
    customLaunchers:{
      HeadlessChrome:{
        base: 'ChromeHeadless',
        flags: ['--no-sandbox']
      }
    },

appears to have worked for us.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ChromeHeadless not starting: timing out when running ng test
Show activity on this post. I am working on an Angular 7 (7.2. 13) app and am having trouble running npm run test...
Read more >
Fixing a Karma Issue With Chrome V93 | by Colton - Medium
The Karma failed to capture a full chrome for testing ... One more benefit of using Headless Chrome is that it gives us...
Read more >
karma-runner/karma - Gitter
Occasionally, component tests will fail with Disconnected (1 times) reconnect failed before timeout of 10000ms . The issue is very difficult to isolate....
Read more >
Speed up Karma and Jasmine tests with ChromeHeadless
The browser is a bit slow for running and in the CI it impacts time of executing, we can speed up our tests...
Read more >
Running nightwatch tests in headless Chrome (Windows)
Increase the timeout. If my config file is fine than there is some issue with your page or test file. Does your browser...
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