Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chrome Warning: Unload event listeners are deprecated and will be removed. #16708

Open
patrickatwsrn opened this issue Feb 12, 2025 · 2 comments
Labels
bug The issue in the code or project, which should be addressed.

Comments

@patrickatwsrn
Copy link

Bug report

Summary

Warning in chrome developer console regarding use of the unload event in
/manager/assets/ext3/adapter/ext/ext-base.js:21

Image

Step to reproduce

Warning shows up on every kind of MODX 3.0 manager page. I'd expect that is also true for modx 2.x (no proof)

Observed behavior

The error points to g = "unload" which ist marked as deprecated in chrome

Ext.lib.Event = function() {
        var v = false, f = {}, z = 0, o = [], d, A = false, k = window, E = document, l = 200, r = 20, p = 0, i = 1, s = 2, w = 3, t = "scrollLeft", q = "scrollTop", g = "unload", y = "mouseover", D = "mouseout", e = function() {
            var F;
            if (k.addEventListener) {
                F = function(J, H, I, G) {
                    if (H == "mouseenter") {
                        I = I.createInterceptor(n);
                        J.addEventListener(y, I, (G))
                    } else {
                        if (H == "mouseleave") {
                            I = I.createInterceptor(n);
                            J.addEventListener(D, I, (G))
                        } else {
                            J.addEventListener(H, I, (G))
                        }
...

Quote from the google docs:

A Permission-Policy for creating unload event listeners will be added.
Initially the default policy will be to allow but Chrome will gradually migrate the default policy to deny creating unload event listeners until it is fully opt-in. The eventual goal is to remove support for unload event.
Source: https://chromestatus.com/feature/5579556305502208

Expected behavior

Use of unload should be removed from ext.js. According to google support it is unreliable and there are also possible performance issues (see source, above).

Environment

MODX version 3.1

@patrickatwsrn patrickatwsrn added the bug The issue in the code or project, which should be addressed. label Feb 12, 2025
@mkschell
Copy link
Member

mkschell commented Feb 18, 2025

Proof of concept that this can be worked around by monkeypatching

# load this before ExtJS is loaded
var originalAddEventListener = EventTarget.prototype.addEventListener;
EventTarget.prototype.addEventListener = function(type, listener, options) {
    // For now, just dump the listener
    if (type === 'unload') return;

    // Call the original addEventListener function
    return originalAddEventListener.apply(this, arguments);
};

We may want to replace the unload event with something else. I'm not super clear on the ramifications of not having an unload event handler in MODX.
We could also choose to target Chrome only, if we're able to be accurate about that.

@smg6511
Copy link
Collaborator

smg6511 commented Feb 18, 2025

Thanks for reporting this. IMO, for the time-being, this is best left alone. This deprecation notice is something one has to seek out in dev tools (as opposed to a warning/error that appears in the console), and is not likely to be seen by most users.

Google is still at a pretty early point in the process of eventually removing the unload listener. The next thing to happen will merely be requiring apps to opt in to the event; I believe this can be handled outside of Ext JS (via the header Permissions-Policy: unload=*). The actual removal is likely far off. In the meantime, if MODX is to move forward, we will have developed a completely different front end (hopefully) before that breaking change occurs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The issue in the code or project, which should be addressed.
Projects
None yet
Development

No branches or pull requests

3 participants