Skip to content

Firefox browser never connected (Cannot read properties of undefined (reading 'browsingContextGetTree')) #31381

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
CastiGiuseppe opened this issue Mar 26, 2025 · 17 comments

Comments

@CastiGiuseppe
Copy link

CastiGiuseppe commented Mar 26, 2025

Current behavior

I'm trying to run tests on Firefox 136.0.3 with cypress version 14.2.0 on windows machine.
I have this error :

Timed out waiting for the browser to connect. Retrying...
Timed out waiting for the browser to connect. Retrying again...
The browser never connected. Something is wrong. The tests cannot run. Aborting...
The browser never connected. Something is wrong. The tests cannot run. Aborting...

Cannot read properties of undefined (reading 'browsingContextGetTree')
TypeError: Cannot read properties of undefined (reading 'browsingContextGetTree')
    at Object.connectToNewSpecBiDi (<embedded>:2764:205513)
    at Object.K (<embedded>:2770:9092)
    at Object.connectToNewSpec (<embedded>:2770:30156)
    at async v.relaunchBrowser (<embedded>:2879:3[86](https://git.vascloud.be/nihii/vidis-webcomponent-tests/-/jobs/509981#L86)03)

Desired behavior

Cypress should run tests on firefox.

Test code to reproduce

N/A

Cypress Version

14.2.0

Node version

22.12.0

Operating System

Windows 11 Entreprise 24H2

Debug Logs

Other

No response

@AtofStryker
Copy link
Contributor

Hi @CastiGiuseppe. Thank you for opening an issue. I tried to reproduce this with https://github.com/AtofStryker/cypress_issue_31381 but was unable to reproduce. The only difference is I am on Windows 10 and not 11. Are you able to give further instruction on how to reproduce the error?

@MikeMcC399
Copy link
Contributor

@CastiGiuseppe

Like @AtofStryker I was not able to reproduce this issue either and I am using Windows 11 24H2. Could you try the following test to see if it fails for you?

git clone https://github.com/cypress-io/github-action
cd github-action
cd examples/browser
npm ci
npm run cy:run:firefox

Logs

Here are the logs showing it working:

DevTools listening on ws://127.0.0.1:55265/devtools/browser/d8b8c3b8-d123-47dd-82fd-d7d5a0a45f29

====================================================================================================

  (Run Starting)

  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Cypress:        14.2.1                                                                         │
  │ Browser:        Firefox 136 (headless)                                                         │
  │ Node Version:   v22.12.0 (C:\Program Files\nodejs\node.exe)                                    │
  │ Specs:          1 found (spec.cy.js)                                                           │
  │ Searched:       cypress/e2e/**/*.cy.{js,jsx,ts,tsx}                                            │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘


────────────────────────────────────────────────────────────────────────────────────────────────────

  Running:  spec.cy.js                                                                      (1 of 1)
before launching browser
{
  name: 'firefox',
  family: 'firefox',
  channel: 'stable',
  displayName: 'Firefox',
  version: '136.0.3',
  path: 'C:\\Program Files\\Mozilla Firefox\\firefox.exe',
  majorVersion: '136',
  isHeadless: true,
  isHeaded: false
}


top window inner w, h is 1173x660
  √ works (2175ms)

  1 passing (4s)


  (Results)

  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Tests:        1                                                                                │
  │ Passing:      1                                                                                │
  │ Failing:      0                                                                                │
  │ Pending:      0                                                                                │
  │ Skipped:      0                                                                                │
  │ Screenshots:  3                                                                                │
  │ Video:        false                                                                            │
  │ Duration:     3 seconds                                                                        │
  │ Spec Ran:     spec.cy.js                                                                       │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘


  (Screenshots)

  -  C:\Users\mikem\AppData\Local\Temp\tmp.xXl5mayn5X\github-action\examples\browser\     (1280x720)
     cypress\screenshots\spec.cy.js\runner.png
  -  C:\Users\mikem\AppData\Local\Temp\tmp.xXl5mayn5X\github-action\examples\browser\     (1091x720)
     cypress\screenshots\spec.cy.js\viewport.png
  -  C:\Users\mikem\AppData\Local\Temp\tmp.xXl5mayn5X\github-action\examples\browser\    (1091x5328)
     cypress\screenshots\spec.cy.js\fullPage.png


====================================================================================================

  (Run Finished)


       Spec                                              Tests  Passing  Failing  Pending  Skipped
  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ ✔  spec.cy.js                               00:03        1        1        -        -        - │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘
    ✔  All specs passed!                        00:03        1        1        -        -        -

@CastiGiuseppe
Copy link
Author

CastiGiuseppe commented Mar 27, 2025

@MikeMcC399 I tried what you explained and it fails again.

Here is the log I have. I don't know if it can help you.

> > [email protected] cy:run:firefox
> cypress run --browser firefox

It looks like this is your first time using Cypress: 14.2.1

√  Verified Cypress! C:\Users\gica\AppData\Local\Cypress\Cache\14.2.1\Cypress

Opening Cypress...


DevTools listening on ws://127.0.0.1:58066/devtools/browser/a9357ede-0666-4819-b9a1-8a2eb7631015

====================================================================================================

  (Run Starting)

  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Cypress:        14.2.1                                                                         │
  │ Browser:        Firefox 136 (headless)                                                         │
  │ Node Version:   v22.12.0 (c:\dev\js\nodejs\node.exe)                                           │
  │ Specs:          1 found (spec.cy.js)                                                           │
  │ Searched:       cypress/e2e/**/*.cy.{js,jsx,ts,tsx}                                            │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘


────────────────────────────────────────────────────────────────────────────────────────────────────

  Running:  spec.cy.js                                                                      (1 of 1)
before launching browser
{
  name: 'firefox',
  family: 'firefox',
  channel: 'stable',
  displayName: 'Firefox',
  version: '136.0.3',
  path: 'C:\\Program Files\\Mozilla Firefox\\firefox.exe',
  majorVersion: '136',
  isHeadless: true,
  isHeaded: false
}

Timed out waiting for the browser to connect. Retrying...
before launching browser
{
  name: 'firefox',
  family: 'firefox',
  channel: 'stable',
  displayName: 'Firefox',
  version: '136.0.3',
  path: 'C:\\Program Files\\Mozilla Firefox\\firefox.exe',
  majorVersion: '136',
  isHeadless: true,
  isHeaded: false
}

Timed out waiting for the browser to connect. Retrying again...
before launching browser
{
  name: 'firefox',
  family: 'firefox',
  channel: 'stable',
  displayName: 'Firefox',
  version: '136.0.3',
  path: 'C:\\Program Files\\Mozilla Firefox\\firefox.exe',
  majorVersion: '136',
  isHeadless: true,
  isHeaded: false
}
>
The browser never connected. Something is wrong. The tests cannot run. Aborting...

The browser never connected. Something is wrong. The tests cannot run. Aborting...

  (Results)

  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Tests:        0                                                                                │
  │ Passing:      0                                                                                │
  │ Failing:      1                                                                                │
  │ Pending:      0                                                                                │
  │ Skipped:      0                                                                                │
  │ Screenshots:  0                                                                                │
  │ Video:        false                                                                            │
  │ Duration:     0 seconds                                                                        │
  │ Spec Ran:     spec.cy.js                                                                       │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘


====================================================================================================

  (Run Finished)


       Spec                                              Tests  Passing  Failing  Pending  Skipped
  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ ×  spec.cy.js                                 0ms        -        -        1        -        - │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘
    ×  1 of 1 failed (100%)                       0ms        -        -        1        -        -

@MikeMcC399
Copy link
Contributor

MikeMcC399 commented Mar 27, 2025

@CastiGiuseppe

Thank you for testing with the example! This works for me on 2 different Windows 11 24H2 systems, so if it fails for you, then there is something different on your system / network.

Did you try uninstalling and re-installing Firefox?

Do you have access to a different Windows 11 system to try on that one?

Are you on a restricted corporate network?

@CastiGiuseppe
Copy link
Author

I'm working on a restricted corporate network.

I will try uninstalling and re-installing Firefox.

I will keep you inform. Thanks

@MikeMcC399
Copy link
Contributor

@CastiGiuseppe

I'm working on a restricted corporate network.

You may need to work with your network admin on this point and I'm wondering if Windows group policies may be causing your issue. I don't have in-depth experience with this, however you might want to try running:

GPRESULT /R

from a Windows cmd or PowerShell terminal to see if any relevant restrictions are shown.

@CastiGiuseppe
Copy link
Author

CastiGiuseppe commented Mar 28, 2025

I re-tried uninstalling and re-installing Firefox and I still have the issue.

@MikeMcC399
Copy link
Contributor

@CastiGiuseppe

I re-tried uninstalling and re-installing Firefox and I still have the issue.

Re-installing was suggested as a precautionary measure. The outstanding points are:

  • Is the problem reproducible on other Windows 11 systems in your environment?
  • Does your network or your system have Windows Group Policies enabled that could affect how the Mozilla Firefox browser runs?

@CastiGiuseppe
Copy link
Author

I did several tries (downgrading cypress & firefox version).

Fortunately it's working with cypress 14.2.1 & Firefox 137

Thanks for your time and help.

@MikeMcC399
Copy link
Contributor

@CastiGiuseppe

It's good to hear that you have Cypress and Firefox working now. So thank you for reporting back! We don't have an explanation why it wasn't working before though it seems.

If you don't need any more help, then I suggest that you close this issue ⬇

@JoostK
Copy link
Contributor

JoostK commented Apr 8, 2025

Also seeing this failure using the latest cypress/included:14.2.1 Docker image (which contains Firefox 136). The environment has restricted network access (effectively none, only connections to a very limited set of hosts are allowed, other connections are silently dropped during the TCP handshake) but it's unclear how to resolve this.

@MikeMcC399
Copy link
Contributor

MikeMcC399 commented Apr 8, 2025

@JoostK

@JoostK
Copy link
Contributor

JoostK commented Apr 8, 2025

@JoostK

Thanks for this suggestion, this is very helpful. I've attempted to make geckodriver available within the Docker image (but through a derived image from cypress/included plus manually downloading the geckdriver binary and setting GECKODRIVER_CACHE_DIR accordingly) but to no avail yet.

Setting DEBUG=cypress:*,cypress-verbose:server:browsers:firefox,cypress-verbose:server:browsers:geckodriver,cypress-verbose:server:browsers:webdriver doesn't give too much information whether geckodriver/webdriver actually starts, although this probably tells me that they don't start at all. I only see the spawning messages from Cypress itself, then silence (except for some CPU usage stats periodically and eventually the retry/failed to start logging).

Note that when running npx geckodriver then geckodriver is properly running, so my custom provisioning of the geckodriver binary does appear to be working (otherwise this would've failed, no internet access here except for npx having access to a private NPM mirror).

The tldr; is that I think that Webdriver doesn't start, judging by how geckodriver appears to be started through webdriver:

// @see https://webdriver.io/docs/capabilities/#wdiogeckodriveroptions
// webdriver starts geckodriver with the correct options on behalf of Cypress
'wdio:geckodriverOptions': geckoDriverOptions,

There's no failure logging to indicate such condition though, so I'm a bit puzzled. Could webdriver have started but be hung, waiting for a network timeout to occur?

@MikeMcC399
Copy link
Contributor

@JoostK

Could webdriver have started but be hung, waiting for a network timeout to occur?

I can't answer this question, sorry!

If you are still having problems, you have re-tested with the latest version Cypress 14.3.0 and you believe this could be a bug in Cypress, then I would recommend that you open a new issue. I would not expect the Cypress.io team to follow up on this closed issue.

@JoostK
Copy link
Contributor

JoostK commented Apr 14, 2025

Having absolutely no insight into what is (or rather isn't) happening as verbose logging doesn't provide any details, I started bisecting Cypress releases. This broke in Cypress 13.5.1, so it's either #30250 or #30324 that broke this. Since these were released together I don't have insight into which of the two actually breaks stuff, although I believe it's the WD.newSession call that never resolves which got introduced in #30324.

Without further debugging insights I cannot provide addition information, having attempted the following:

  • DEBUG=cypress:*,cypress-verbose:server:browsers:firefox,cypress-verbose:server:browsers:geckodriver,cypress-verbose:server:browsers:webdriver (and even DEBUG=* at some point)
  • WDIO_DEBUG=1
  • WDIO_LOG_LEVEL=debug

The latter two were extracted from webdriver code but didn't result in additional logging. Note that the geckodriver binary has been provisioned in the image (and GECKODRIVER_CACHE_DIR set to pin its location in the image) but it appears the issue occurs in webdriver already.

@JoostK
Copy link
Contributor

JoostK commented Apr 14, 2025

Looking through WD.newSession, it calls into @wdio/utils's startWebDriver which calls into setupPuppeteerBrowser. Since the binary path isn't set, it delegates to canDownload in @puppeteer/browsers. This subsequently makes a HEAD request:

https://github.com/puppeteer/puppeteer/blob/bfc34f5916579351700b52349fd612935cd44f64/packages/browsers/src/install.ts#L445-L460

I think this explains why there's no further logging, as the last message I observe is INFO webdriver: Initiate new session using the WebDriver protocol and webdriver's first subsequent logging line appears to be

https://github.com/webdriverio/webdriverio/blob/61c5243243942d8fc9899d9e999cd0d25ddcbde2/packages/wdio-utils/src/node/utils.ts#L228

which executes after canDownload. So this is indeed a blind spot in webdriver's logging in case the HEAD request never completes, causing a stall.

@JoostK
Copy link
Contributor

JoostK commented Apr 14, 2025

More updates on the update; I glanced over the following logic in setupPuppeteerBrowser:

https://github.com/webdriverio/webdriverio/blob/61c5243243942d8fc9899d9e999cd0d25ddcbde2/packages/wdio-utils/src/node/utils.ts#L184-L206

which avoids an ad-hoc download of a Puppeteer browser when the browser is already present. This is the case with cypress/included, and it does indeed find it.

Then I found:

https://github.com/webdriverio-community/node-geckodriver/blob/27b1e49569cecdff184e243ad3a0c17d3407547b/src/index.ts#L13C9-L15

which exposes the relevance of the GECKODRIVER_PATH environment variable instead of GECKODRIVER_CACHE_DIR. Setting GECKODRIVER_PATH fixes the issue! GECKODRIVER_CACHE_DIR is irrelevant because webdriver passes an explicit cacheDir to geckodriver's start function, meaning that GECKODRIVER_CACHE_DIR isn't considered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants