Closed Bug 1564930 Opened 6 months ago Closed 6 months ago

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


(Firefox :: Untriaged, defect)

69 Branch
Not set



Firefox 70
Tracking Status
firefox70 --- fixed


(Reporter: mail, Assigned: mail)



(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();"GET", location, false);
var a = x.send();
x.responseType = "arraybuffer";

Example taken from

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

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
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)
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.