cypress icon indicating copy to clipboard operation
cypress copied to clipboard

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

Open cacieprins opened this issue 9 months ago • 0 comments

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

cacieprins avatar May 15 '24 18:05 cacieprins