cypress icon indicating copy to clipboard operation
cypress copied to clipboard

Opt out of 'unload' event deprecation

Open cacieprins opened this issue 9 months ago • 0 comments

What would you like?

Chrome is deprecating the unload event. (see also: https://github.com/cypress-io/cypress/issues/29241)

Why is this needed?

Cypress uses the unload event during AUT navigation, and emits a window:unload event that can be hooked into from tests. With unload forcibly deprecated, Cypress no longer works as expected, and the window:unload event will not fire.

Other

Background

To prevent Cypress runs from failing while we work to remove or find alternatives to using unload, we can leverage a permissions policy option added to Chrome 117 to preserve usage. This is not a permanent fix, and this permissions policy option will be removed in a future version of Chrome. This just gives us breathing room.

Potential complication: Documentation only provides a solution for single-layer cross-domain iframes. We will probably be able to make this work when the AUT is a cross-domain iframe with the App, but it is unlikely that we will be able to force unload events to be enabled when the AUT iframe includes a sub-iframe that is cross-domain with the AUT iframe.

Acceptance Criteria

  • Top level Cypress URL returns with a Permissions-Policy: unload=(self,"${AUT_URL}") header, where AUT_URL is the url that will be loaded in the AUT iframe
  • The AUT iframe has an allow="unload" property
  • Cypress' proxy sets Permissions-Policy: unload=self on AUT responses
  • Cypress' proxy modifies iframes in the AUT to include the allow="unload" property

cacieprins avatar May 06 '24 14:05 cacieprins