Back to Browse

Stub the BeforeUnloadEvent.prototype.preventDefault Method

78 views
Apr 27, 2026
6:55

If the application shows the "Leave page" popup using the "e.preventDefault()" method call in the "beforeunload" event handler, we can confirm it in the Cypress tests using a stub on the "BeforeUnloadEvent.prototype.preventDefault". This video shows the solution, for more read the blog post "window.onbeforeunload and Cypress" at https://glebbahmutov.com/blog/onbeforeunload/

Download

0 formats

No download links available.

Stub the BeforeUnloadEvent.prototype.preventDefault Method | NatokHD