Skip to content
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

13.0.0+ hangs during cypress open when 'beforeunload' prevents default to prevent browser from closing with use of cypress-real-events #28553

Open
jennifer-shehane opened this issue Dec 19, 2023 · 3 comments
Labels

Comments

@jennifer-shehane
Copy link
Member

jennifer-shehane commented Dec 19, 2023

Current behavior

When there's a listener for 'beforeunload' that has preventDefault to prevent the page from closing, cypress run will hang starting in 13.0.0 in Chrome (using 120) when a call is made to a custom command from the cypress-real-events plugin.

The dialog on beforeunload requires sticky activation in order to display. A simulated click in Cypress wouldn’t trigger this, but the realEvents does

You can see when this is run locally that this popup appears and that's why it's hanging.

Screen Shot 2023-12-19 at 1 06 14 PM

And this popup also occurs when you try to exit the browser during open mode.

Screen Shot 2023-12-19 at 1 40 07 PM

Desired behavior

Hanging is bad. We should not be hanging here.

Long term: we should look for all open dialogs and close them and also offer an API for users to hook into to test dialog behavior (where the automatic closing behavior is bypassed)

Short term: When Cypress is the one in control of navigating away from the page (we are closing the tab, closing the browser, or visiting about:blank during testIsolation) we should search for open dialogs that were triggered via beforeunload using CDP to detect open dialogs and close the dialogs while printing to debug logs that we've manually closed a dialog and what type.

Workaround?

Theoretically I believe someone could hook into CDP to detect dialog open https://chromedevtools.github.io/devtools-protocol/tot/Page/#event-javascriptDialogOpening and then dismiss it https://chromedevtools.github.io/devtools-protocol/tot/Page/#method-handleJavaScriptDialog I'm a little unsure of the timing here though since the browser is already closing at this point, whether it would run

Test code to reproduce bug on close of entire browser

cypress run --browser=chrome

test.cy.js

it('test', () => {
  cy.visit('index.html')
  // this can be any command! Try realType or realPress, etc
  cy.get('div').realClick()
})
// hangs after test finishes

index.html

<html>
<script>
  window.addEventListener('beforeunload', function (e) {
    e.preventDefault();
  });
  </script>
<body>
  <div></div>
</body>
</html>

package.json

{
  "devDependencies": {
    "cypress": "13.0.0",
    "cypress-real-events": "^1.11.0"
}

Test code to reproduce bug navigation during testIsolation

cypress run --browser=chrome

test.cy.js

it('test', () => {
  cy.visit('index.html')
  // this can be any command! Try realType or realPress, etc
  cy.get('div').realClick()
})

// hangs here
it('test', () => {
  cy.visit('index.html')
  // this can be any command! Try realType or realPress, etc
  cy.get('div').realClick()
})

index.html

<html>
<script>
  window.addEventListener('beforeunload', function (e) {
    e.preventDefault();
  });
  </script>
<body>
  <div></div>
</body>
</html>

package.json

{
  "devDependencies": {
    "cypress": "13.0.0",
    "cypress-real-events": "^1.11.0"
}

Cypress Version

13.0.0 (and before for testIsolation issue)

@jennifer-shehane jennifer-shehane added v13.0.0 🐛 Issue present since 13.0.0 type: bug labels Dec 19, 2023
@jennifer-shehane jennifer-shehane changed the title 13.0.0+ hangs during cypress open when 'beforeunload' prevents default to prevent browser from closing. 13.0.0+ hangs during cypress open when 'beforeunload' prevents default to prevent browser from closing with use of cypress-real-events Dec 19, 2023
@satya081
Copy link

satya081 commented May 2, 2024

any updates on this issue?

@mihhail-m
Copy link

still in cypress 13.13.3 and Chrome 128 👍

@NatalieRibeiro
Copy link

Any updates on this please?
Like people mention above, sometimes the same script will work fine and then on following executions it will get stuck there for hours. Very hard to predict when it will happen or to find a workaround it.

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

No branches or pull requests

4 participants