Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HeadlessChrome with Chrome 83 disconnected with Karma

I perform some unit-tests with Karma, Sinon and Mocha. It was working fine and for one month, I have some issues running these unit-tests. I have an error with HeadlessChrome. Indeed, it shows this error:

HeadlessChrome 83.0.4103 (Windows 10.0.0) ERROR
Disconnected, because no message in 30000 ms.

I have this karma configuration:

module.exports = function (config) {
  config.set({
    // Others configs
    ...
    port: 9876,
    browsers: ['ChromeHeadlessNoSandbox'],
    customLaunchers: {
      ChromeHeadlessNoSandbox: {
        base: 'ChromeHeadless',
        flags: [
          '--no-sandbox', // required to run without privileges in docker
          '--user-data-dir=/tmp/chrome-test-profile',
          '--disable-web-security'
        ]
      }
    },
    captureTimeout: 10000,
    plugins: [
      'karma-mocha', 'karma-mocha-reporter', 'karma-junit-reporter', 'karma-chrome-launcher',
      'karma-typescript', 'karma-html-reporter'
    ]
  });
};

I found two ways to fix it:

  • Downgrade to version 81.
  • Open a page in localhost:9876 in the browser.
  • Change the karma config (browsers and flags property):
module.exports = function (config) {
  config.set({
    // Others configs
    ...
    port: 9876,
    browsers: ['Chrome'],
    flags: [
      '--no-sandbox', // required to run without privileges in docker
      '--user-data-dir=/tmp/chrome-test-profile',
      '--disable-web-security'
    ],
    captureTimeout: 10000,
    plugins: [
      'karma-mocha', 'karma-mocha-reporter', 'karma-junit-reporter', 'karma-chrome-launcher',
      'karma-typescript', 'karma-html-reporter'
    ]
  });
};

How could I use ChromeHeadless again ? Indeed, it was nice because all unit-tests was running in background whereas now it opens the browsers, performs the tests and closes it.

like image 436
PierBJX Avatar asked Oct 16 '22 02:10

PierBJX


1 Answers

We had the same surprise at my job. Our tests started to fail at the end of June which was a new Chrome 83 stable release.

They definitely broke something, you can follow-up here : https://bugs.chromium.org/p/chromium/issues/detail?id=1090988

EDIT:

So to answer properly, if you can go back to before Chrome 83, that will fix it for now. However, I don't know for our side of things, I would need to find a new docker image, which is not nice.

like image 133
MLefebvreICO Avatar answered Oct 27 '22 10:10

MLefebvreICO