jquery / jquery

jQuery JavaScript Library
https://jquery.com
MIT License
58.93k stars 20.62k forks source link

Permissions policy violation due to unload event #5430

Closed johnvang closed 2 months ago

johnvang commented 2 months ago

Description

Hi, I am on verstion 3.6.3. I have an application that opens an iFrame in a window that I am testing with the chrome flag for unload deprecation enabled (https://developer.chrome.com/docs/web-platform/deprecating-unload and chrome://flags/#deprecate-unload).

With the flag enabled, I am encountering permissions policy violation errors when opening and closing the iFrames, because the setDocument() method is attempting to attach the unload event to the iFrame.

`if ( preferredDoc != document && ( subWindow = document.defaultView ) && subWindow.top !== subWindow ) {

    // Support: IE 11, Edge
    if ( subWindow.addEventListener ) {
        subWindow.addEventListener( "unload", unloadHandler, false );

    // Support: IE 9 - 10 only
    } else if ( subWindow.attachEvent ) {
        subWindow.attachEvent( "onunload", unloadHandler );
    }
}`

Is there a way avoid this error without having to update jQuery? If I need to fire setDocument(), can I do it on my own in my iFrame unloading?

Link to test case

timmywil commented 2 months ago

Thanks for opening an issue. I see you asked if there is a way to avoid this without updating jQuery, but I would still suggest updating jQuery to 3.7.1, which limits the unload handler to IE and Edge Legacy. Upgrading from 3.6.3 to 3.7.1 should not have compatibility issues. setDocument fires on load so there isn't really another way around it.