cypress: Error: could not find CRI target (Cypress 4.6.0)

Current behavior:

cypress run fails with the following error on Chrome:

Cypress failed to make a connection to the Chrome DevTools Protocol after retrying for 50 seconds.

This usually indicates there was a problem opening the Chrome browser.

The CDP port requested was 26359.

Error details:

Error: could not find CRI target
    at lazyAssLogic (C:\Users\user\AppData\Local\Cypress\Cache\4.6.0\Cypress\resources\app\packages\server\node_modules\lazy-ass\index.js:110:14)
    at Object.lazyAss (C:\Users\user\AppData\Local\Cypress\Cache\4.6.0\Cypress\resources\app\packages\server\node_modules\lazy-ass\index.js:115:28)
    at findStartPage (C:\Users\user\AppData\Local\Cypress\Cache\4.6.0\Cypress\resources\app\packages\server\lib\browsers\protocol.js:56:23)

Full log is also attached.

Note that this doesn’t appear to be 100% consistent. With the below example I am seeing this maybe 25% of the time.

We had previously observed this before, and upgraded to both 3.8.3 as a result of: https://github.com/cypress-io/cypress/issues/6053

Then more recently, upgraded to 4.6.0 as a result of: https://github.com/cypress-io/cypress/issues/6518

Still observing on 4.6.0 as below though

Desired behavior:

Execution should not fail in this manner.

Test code to reproduce

  1. Clone https://github.com/stevejefferies/cypress-test-tiny
  2. Run cypress:run as defined in package.json e.g. npm run cypress:run

Versions

Cypress: 4.6.0 Browser: Chrome 83 OS: Windows 10

Debug Log

debug_log.txt

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 8
  • Comments: 32 (5 by maintainers)

Most upvoted comments

Should have added to my comment above, for those looking for a potential workaround adding the disable-gpu flag on browser launch (plugins/index.js) seems stable for me at least locally: 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;
    }
  });
}

@nids2307 try below code in Plugins/index.js its working

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

Since chrome 83 was installed we also have this issue.

2020-05-29T10:15:14.1447528Z Failed to connect to Chrome, retrying in 1 second (attempt 60/62)
2020-05-29T10:15:14.1447578Z Failed to connect to Chrome, retrying in 1 second (attempt 61/62)
2020-05-29T10:15:14.1447611Z Failed to connect to Chrome, retrying in 1 second (attempt 62/62)
2020-05-29T10:15:14.1447646Z Cypress failed to make a connection to the Chrome DevTools Protocol after retrying for 50 seconds.
2020-05-29T10:15:14.1447669Z 
2020-05-29T10:15:14.1447719Z This usually indicates there was a problem opening the Chrome browser.
2020-05-29T10:15:14.1447827Z 
2020-05-29T10:15:14.1447858Z The CDP port requested was 52137.
2020-05-29T10:15:14.1447878Z 
2020-05-29T10:15:14.1447906Z Error details:
2020-05-29T10:15:14.1447941Z 
2020-05-29T10:15:14.1447970Z Error: could not find CRI target
2020-05-29T10:15:14.1448012Z     at lazyAssLogic (C:\Users\ZMSAAZU002\AppData\Local\Cypress\Cache\4.7.0\Cypress\resources\app\packages\server\node_modules\lazy-ass\index.js:110:14)
2020-05-29T10:15:14.1448064Z     at Object.lazyAss (C:\Users\ZMSAAZU002\AppData\Local\Cypress\Cache\4.7.0\Cypress\resources\app\packages\server\node_modules\lazy-ass\index.js:115:28)
2020-05-29T10:15:14.1448121Z     at findStartPage (C:\Users\ZMSAAZU002\AppData\Local\Cypress\Cache\4.7.0\Cypress\resources\app\packages\server\lib\browsers\protocol.js:56:23)

Did some digging on this. This looks to be a Chrome issue in that the underlying issue observed (no targets returned from call to CDP.List in chrome remote interface) can be replicated outside of Cypress completely. e.g.:

const CDP = require('chrome-remote-interface');
const { spawn  } = require("child_process");

const port = 8004
const stable = "chrome.exe"
const chrome = spawn(stable, ['about:blank', 
'--headless', 
`--remote-debugging-port=${port}`, 
'--remote-debugging-address=127.0.0.1'
]);

(function retryLoop(i) {
    setTimeout(function() {
        CDP.List({port: port}, (err, targets) => {
            console.log(err)
            if (!err) {
                console.log(targets);
            }
        });              
      if (--i) retryLoop(i);
    }, 3000)
  })(10);

results in an empty list - as you see when this fails in Cypress.

Digging further, it appears to be down to the Chrome renderer child process crashing. There are numerous open tickets with the Chromium project which highlight this issue so its hard to determine the actual stability of this. But a few options I tried from the issues in the Chromium project do seem to have solved this from my limited local testing (Win 10 only):

  1. disable gpu when launching Chrome on windows by adding the --disable-gpu flag on browser launch, as Cypress already does for Chrome on linux
  2. specify a given GL to use, using --use-gl=desktop/swiftshader both seem to give stable results locally
  3. Chrome 84 (in beta, tested: 84.0.4147.38) seems to be stable to this issue as well
  4. (and slightly weirdly) not launching “about:blank” instead using a different page, also seems to be more stable, although I cannot see why this would be.

Is there a reason why Cypress only sets --disable-gpu for linux (here)? Happy to make this fix.

I also found the same error as @stevejefferies found

I am facing this issue for both chrome and edge browser, It’s working on cypress open UI but not able to run on the headless browser and not in CI environment also.

Any update on this issue ?