13.0.0+ hangs during cypress open
when 'beforeunload' prevents default to prevent browser from closing with use of cypress-real-events
#28553
Labels
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 thecypress-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 doesYou can see when this is run locally that this popup appears and that's why it's hanging.
And this popup also occurs when you try to exit the browser during open mode.
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
index.html
package.json
Test code to reproduce bug navigation during testIsolation
cypress run --browser=chrome
test.cy.js
index.html
package.json
Cypress Version
13.0.0 (and before for testIsolation issue)
The text was updated successfully, but these errors were encountered: