cypress: Timed out waiting for the browser to connect - Cannot read properties of null (reading 'getWebSocketDebuggerUrl')
Current behavior
Since updating to Node v20.9.0 and Cypress v13.6.0, my tests are failing with a timeout error. The problem only occurs in the CI (gitlab-runner 16.5.0).
Running: login/login.cy.ts (1 of 9)
Timed out waiting for the browser to connect. Retrying...
Cannot read properties of null (reading 'getWebSocketDebuggerUrl')
TypeError: Cannot read properties of null (reading 'getWebSocketDebuggerUrl')
at Object.open (:4454:111131)
at async Object.open (:4460:27335)
at async v.relaunchBrowser (:4526:36933)
Desired behavior
No response
Test code to reproduce
Cypress Version
13.6.0
Node version
20.9.0
Operating System
public.ecr.aws/cypress-io/cypress/base:20.9.0
Debug Logs
No response
Other
Browser: Electron 114 (headless)
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 11
- Comments: 28 (6 by maintainers)
We’ve worked around it by setting the
CYPRESS_INTERNAL_BROWSER_CONNECT_TIMEOUTenvironment variable to300000, a tip we picked up from #26936.Oddly enough, I believe we were seeing this behavior previously with Chrome, and it only recently started happening with Electron. I think Electron used to wait to start looking for the browser until after compilation had finished.
We have this problem as well. Going from
13.6.4to13.2.0works for us as well, but certainly just a workaround until the problem is fixed.If it helps, I have cypress locked to
13.2.0and that appears to work.Every time I try to upgrade, it works locally, but fails in CI (github-actions).
I’m having a lot of issues reproducing this in the wild, but since @UlanaXY sent over some debug logs, I was able to go through those and get a rough idea as to what is happening. From what I can see it looks related to the work done in #28180 (and maybe colliding with #25898?).
Going through the logs, I can see that the browser has two tabs set up at time of log availability (i.e. two targets). This is not normal from what I can see on regular runs. There should only be one target tab, plus the debugger port. The two targets in this case are as follows:
We can also see later on in the logs that after:browser:launch is NOT set up (at least according to the logs).
We can see a new process is being opened, but there is likely a launchAttempt mismatch, so the process is killed. When this happens:
It looks like 5CF5B7DE5262708EB8D79991A162D0D4 is the active target but its CRI client is now closed, as we can see that later on we get the log that the CRI client is disconnected, but will not reconnect to it because its closed, meaning when we try to access the getWebSocketDebuggerUrl on target 5CF5B7DE5262708EB8D79991A162D0D4, it is
nulland throws the error.Since this is in the general CRI client and likely a bug with how we are handling multiple browser/tab instances / mismatch on the active instance, it explains why its very intermittent (since it requires multiple tabs to be active) and can happen in any supported browser. (why we see it in electron and chromium).
Hypothetically a user could create a new tab with the puppeteer plugin which could have some side effects. @UlanaXY, @danielbayerlein or anyone else confirm if you are using this feature or not?
My best guess is that the correct behavior would be only one target from the start, and if two are required for other reasons (possibly the puppeteer plugin or a user clicked on an external link that opened another tab?), the CRI client that needs to be disconnected also needs to be the target that is destroyed.
Is anyone else able to send debugger logs to verify similar behavior? Since I can’t reproduce the issue, @UlanaXY 's logs are the best I have to go off of for now. Even better if someone has a reproducible example!
Actually I may have tracked this down to this PR: https://github.com/cypress-io/cypress/pull/28180 which means it would have been introduced in 13.5.0. That doesn’t exactly account for people saying that updating to 13.4.0 doesn’t resolve the issue though.
My best guess is that
CYPRESS_INTERNAL_BROWSER_CONNECT_TIMEOUTis giving significant time for the browser process to get going, so the likelihood of orphaned processes goes down significantly. For our mock reproduction, we essentially remove this option to make the timeout super short on the first launch to near guarantee an orphaned process https://github.com/cypress-io/cypress/commit/4d80ef8dd1608564769a95edb1a13016ddab0a22.I’ve been working on @ryanthemanuel on the issue and it looks like we can mock the reproduction of the issue 🎉 (specifically to electron) to force the first instance of the browser to time out rapidly and create an orphaned browser process https://github.com/cypress-io/cypress/commit/4d80ef8dd1608564769a95edb1a13016ddab0a22.
A possible solution might be to preserve the CRI client in the case of electron since the browser instance is really shared across windows, so the CRI client should be the same. Still confirming and testing…
Any chance this issue can get some love? We encounter this error multiple times a day with Gitlab CI v16.10.2-ee and Cypress v13.6.3. I cannot downgrade to a working version of Cypress (v13.2.0) because we need TS features from the most recent version.
It’s like a 50/50 shot if this appears on any given CI run, and I’m not being hyperbolic
We’re also using the
CYPRESS_INTERNAL_BROWSER_CONNECT_TIMEOUT=300000flag and it works most of the time but still reproduces from time to time. This doesn’t fix the issue entirely.Hi @cg-roling, how did you set the
CYPRESS_INTERNAL_BROWSER_CONNECT_TIMEOUvariable as setting it inCypress.config.jsor to the cypress run API does not seem to be working?