Closed Bug 1888094 Opened 3 months ago Closed 3 months ago

Missing window.event in XHR callbacks

Categories

(Core :: DOM: Events, defect)

defect

Tracking

()

RESOLVED FIXED
126 Branch
Tracking Status
firefox126 --- fixed

People

(Reporter: jgraham, Assigned: smaug)

References

(Blocks 2 open bugs, )

Details

Attachments

(1 file)

We don't define window.event object in XHR callbacks, representing the ProgressEvent that is passed in to the callback function.

From https://bugzilla.mozilla.org/show_bug.cgi?id=1888001#c3:

It seems it's an issue on firefox because of how we handle the global event object on the window ( which is deprecated btw ). Here is a snippet from some code on the website.

function saveDependant() {
    var n, t;
    validateForm() &&
        ((n = new XMLHttpRequest()),
        n.open("POST", "/CustomerProfile/SaveDependent"),
        (n.onload = () => handleSaveDependantReponse(JSON.parse(event.target.response))),
        (t = new FormData(document.getElementById("addDependent"))),
        n.send(t));
}

This code fails with the error: event is undefined in this case.
It fails in firefox and passes in chrome/safari. Not sure if we can fix this, but this is really not how you usually access the xhr response. It's passed as an argument to onload so there is no need to access the global one.

Here is a codepen to reproduce this issue. On firefox you should see an error message in the console.

Blocks: 1888097
See Also: → 218415
Assignee: nobody → smaug
Attachment #9393506 - Attachment description: WIP: Bug 1888094 - Missing window.event in XHR callbacks, r=edgar → Bug 1888094 - Missing window.event in XHR callbacks, r=edgar
Status: NEW → ASSIGNED
Pushed by opettay@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/469884ac63bc
Missing window.event in XHR callbacks, r=edgar
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/45399 for changes under testing/web-platform/tests
Status: ASSIGNED → RESOLVED
Closed: 3 months ago
Resolution: --- → FIXED
Target Milestone: --- → 126 Branch
Upstream PR merged by moz-wptsync-bot
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: