Closed Bug 1564930 Opened 6 months ago Closed 6 months ago

Improve error messages for XMLHttpRequest state must not be LOADING or DONE

Categories

(Firefox :: Untriaged, defect)

69 Branch
All
Unspecified
defect
Not set

Tracking

()

RESOLVED FIXED
Firefox 70
Tracking Status
firefox70 --- fixed

People

(Reporter: mail, Assigned: mail)

Details

Attachments

(1 file)

User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:69.0) Gecko/20100101 Firefox/69.0

Steps to reproduce:

Set the responseType of an XHR after calling send() (which is illegal):

var x = new XMLHttpRequest();
x.open("GET", location, false);
var a = x.send();
x.responseType = "arraybuffer";

Example taken from https://searchfox.org/mozilla-central/rev/40ef22080910c2e2c27d9e2120642376b1d8b8b2/dom/tests/mochitest/bugs/test_onerror_message.html#59-62

Actual results:

The error

InvalidStateError: XMLHttpRequest state must not be LOADING or DONE.

Is raised.

Expected results:

Firefox should have told the user/developer what it is they did wrong.

Currently, the error message looks like an internal Firefox error, instead of like a user mistake.

This can lead to confusion, like in bug 1540574.

Other browsers do this better. For example, Chromium shows this:

Uncaught DOMException: Failed to set the 'responseType' property on 'XMLHttpRequest': The response type cannot be set if the object's state is LOADING or DONE.

This states what the user did and why it's illegal.

We should improve it in Firefox to be similar.

The previous error message suggested that this is an internal error message
pointing out a bad state in the XHR state machine, when in fact this is
a user error (calling overrideMimeType() or setting responseType() after
send()).

This commit improves and disambiguates the error messages, pointing out to
the user what they did wrong, like other browsers do.

Hardware: Unspecified → All
Keywords: checkin-needed

My patch was reviewed and accepted, now I just need somebody to land it for me :)

Flags: needinfo?(tgrabowski)

Pushed by apavel@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/6a357badc190
Improve "XHR must not be LOADING or DONE" error messages. r=baku

Keywords: checkin-needed

(In reply to Niklas Hambüchen from comment #3)

My patch was reviewed and accepted, now I just need somebody to land it for me :)

Your patch has been landed.

Flags: needinfo?(tgrabowski)
Status: UNCONFIRMED → RESOLVED
Closed: 6 months ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 70
You need to log in before you can comment on or make changes to this bug.