cypress: Failing to reliably connect to Chrome on 4.7.0 when using -b chrome --headless

When upgrading to 4.7.0 (from 4.6.0) we are getting error messages when connecting to chrome about 50-75% of the time, this was not a problem before 4.7.0 (we have used Cypress for a couple of years now).

It only happens when we use -b chrome --headless

image

Versions

4.7.0 Windows 10 Chrome 83

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 2
  • Comments: 35 (1 by maintainers)

Most upvoted comments

I get this issue commonly on macOS Catalina and the latest Cypress versions. Not sure how to replicate, but the fix is to kill the orphaned Chrome process.

I’m getting this error locally as well. I’m running MacOS BigSur 11.5, Chrome Version 92.0.4515.107, Cypress 7.5.0. It only occurs when I’m not running headless. I can run headless just fine.

Edit: restarting my machine seems to have fixed my issue.

@eabusharkh0 something like the following in plugins/index.js: Cypress 4+:

module.exports = (on, config) => {
  on('before:browser:launch', (browser, launchOptions) => {
    if (browser.name === 'chrome' && browser.isHeadless) {
      launchOptions.args.push('--disable-gpu');
      return launchOptions
    }
  });
}

Or before Cypress 4:

module.exports = (on, config) => {
  on('before:browser:launch', (browser, args) => {
    if (browser.name === 'chrome' && browser.isHeadless) {
      args.push(
        '--disable-gpu'
      );
      return args;
    }
  });
}

Still experiencing this problem on version 7.0.1, MacOS Catalina with Chrome 89. Already restarted computer, run npx cypress cache clear and npx cypress install multiple times. Added the following code to plugins/index.js but still not connected:

on('before:browser:launch', (browser, launchOptions) => {
        launchOptions.args.push('--disable-gpu')

        return launchOptions
})

Can anyone help?

Seeing this a lot (on Gitlab CI) after upgrading to 7.1.0 with the workaround outlined above:

  Running:  forms/simple/contact-form.spec.js                                  (1 of 5)
Failed to connect to Chrome, retrying in 1 second (attempt 18/62)
...
Failed to connect to Chrome, retrying in 1 second (attempt 45/62)
Timed out waiting for the browser to connect. Retrying...
Timed out waiting for the browser to connect. Retrying again...

@eabusharkh0 Change it to launchOptions.args.push(‘–disable-gpu’);

@eabusharkh0 I believe that should be ‘disable-gpu’ not ‘another-arg’. another-arg was just an example of adding an argument.