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

Created on 1 Jun 2020  路  29Comments  路  Source: cypress-io/cypress

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

windows chrome needs information

Most helpful comment

@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;
    }
  });
}

All 29 comments

Experiencing this as well. I am seeing this issue when running tests headless and headed in chrome.

Versions
4.7.0
Windows 10
Chrome 83

I am also getting same issue

We're also seeing this problem. My colleagues and I use Windows 10 but we also see it on our automated test job running on Windows server 2012 R2. Both use Chrome v. 83.0. Initially when this started happening we were using Cypress version 4.7. Then we tried running lower versions - 4.6, 4.5. Both exhibit the issue.

Same issue here. Running Cypress 4.7.0 on Windows 10.
Running against Chrome 83 with --headless

Not all runs have the issue. First run works but after that 90%+ has the connection problem.

For me first test passed, but next failed with that issue
Explored in 4.7.0 and 4.6.0 (windows 10)
image

I think this is a copy of #7450
It is rather blocking, as Google makes it impossible to downgrade to an earlier version of chrome. And yes, Electron is a kind of workaround, but it almost doubles the run duration.

Getting this as well, I just updated to Windows 10 2004 not sure if related. Sometimes fails on the first test other times it is after 10 tests run.

Following this thread as it's affecting all my chrome headless tests with Cypress 4.7.0.

Thank you @stevejefferies, adding the --disable-gpu flag to 'before:browser:launch' seems to do the trick for me!

@PetMou which file do you add the --disable-gpu flag to? index.js file inside the plugins folder? also can you share what that code looks like please?

We're seeing this on RHEL on our jenkins (latest and greatest) when running cypress as a container. Works fine in 4.6.0. Had the same problem on 3.7.0 which we upgraded from today.

Very random problem.

@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;
    }
  });
}

@stevejefferies That did the trick. Thanks for the work around.

@stevejefferies thank you so much, just a side note, I get a warning after adding your code snippet in the index.js upon execution:
Deprecation Warning: The before:browser:launch plugin event changed its signature in version 4.0.0

The before:browser:launch plugin event switched from yielding the second argument as an array of browser arguments to an options object with an args property.

We've detected that your code is still using the previous, deprecated interface signature.

This code will not work in a future version of Cypress. Please see the upgrade guide: https://on.cypress.io/deprecated-before-browser-launch-args

if you click on the link, it says cypress no longer support the second argument being an array but instead it should look something like this (you can click on the link and read all the details as well):
Before The second argument is no longer an array.

on('before:browser:launch', (browser, args) => {
// will print a deprecation warning telling you
// to change your code to the new signature
args.push('--another-arg')

return args
})
After Access the args property off launchOptions

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

return launchOptions
})

@eabusharkh0 good catch, updated above with 4.x and 3.x versions of the snippet

@stevejefferies I'm still getting the warning in my intellij IDE even after updating the code snippet, any idea on why Cypress is still showing the warning?
image

@eabusharkh0 Shouldn't it be launchOptions.args.push('--another-arg')

Great! This fixes the issue for me as well.
I thought that this option was a default in Cypress?
Guess I was wrong...

My tests fail when implementing this workaround.

@shutchison-bai Strange, I have over 500 tests passed. Are you comparing screen captures maybe or something like that?

@WayneHiller, I rearrange some code in my plugins/index.js file. The workaround appears to be working now. Thanks!

Has anyone noticed a performance hit when specifying --disable-gpu on Chrome? My tests seems to run at about the same speed.

@WayneHiller, My tests run about the same speed as well.

@WayneHiller, here it is a bit slower, but not much (about 3 minutes extra for a run taking about 30 minutes). Nothing dramatic

@WayneHiller when I update the line to use "--another-arg", my tests won't run at all, screenshot is down below, any ideas?
image
image

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

@WayneHiller thank you, I switched it back to disable-gpu, the tests run but I still get the warning for some reason, any idea why?
image

@eabusharkh0 Change it to launchOptions.args.push('--disable-gpu');

@WayneHiller thank you so much, that did the trick!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

carloscheddar picture carloscheddar  路  3Comments

brian-mann picture brian-mann  路  3Comments

tahayk picture tahayk  路  3Comments

brian-mann picture brian-mann  路  3Comments

scottcrowe picture scottcrowe  路  3Comments