cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
47.05k stars 3.18k forks source link

Emit `window:pageshow` and `window:pagehide` events #29523

Open cacieprins opened 6 months ago

cacieprins commented 6 months ago

What would you like?

Cypress should emit window:pageshow and window:pagehide lifecycle events for the AUT.

Why is this needed?

Chrome is progressively deprecating / preventing window 'unload' events and event listeners (see: https://developer.chrome.com/docs/web-platform/deprecating-unload ). `

In preparation for unload being deprecated, Cypress is migrating to pagehide as a proxy for the unload event. With #29525, the window:unload event will be emitted when pagehide is triggered rather than when unload is triggered. As a next step in deprecating Cypress' window:unload, and to keep our API aligned with standards, we need to emit window:pagehide.

There are potential issues with how Cypress determines pageload with the load event. If a page is loaded from the back/forward cache, the load event may not fire (definitively for the top frame; unknown if this is applied to child frames). We should emit window:pageshow in addition to window:load, to provide the additional option to users and keep the load/unload path balanced.

See flowchart: https://developer.chrome.com/docs/web-platform/page-lifecycle-api/image/page-lifecycle-api-state.svg

Other

No response

cypress-app-bot commented 2 days ago

This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided.