Missing window.event in XHR callbacks
Categories
(Core :: DOM: Events, defect)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox126 | --- | fixed |
People
(Reporter: jgraham, Assigned: smaug)
References
(Blocks 2 open bugs, )
Details
(Keywords: webcompat:platform-bug)
Attachments
(1 external 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.
| Assignee | ||
Comment 1•2 years ago
|
||
Updated•2 years ago
|
Comment 4•2 years ago
|
||
| bugherder | ||
Updated•2 years ago
|
Description
•