mootools / mootools-core

MooTools Core Repository
https://mootools.net
2.65k stars 511 forks source link

NS_ERROR_FAILURE XMLHttpRequest exception #2809

Closed mrf345 closed 5 years ago

mrf345 commented 5 years ago

Hello there, I'm new to mootools so bear with me please :) I'm having a strange issue while E2E testing. I'm using mootools 1.4.0 with Firefox 45.0.1 While attempting XMLHttpRequest this exception gets raised:

Exception { message: "", result: 2147500037, name: "NS_ERROR_FAILURE", filename: "http://127.0.0.1:8000/mootools.js", lineNumber: 5706, columnNumber: 0, data: null, stack: "this.Request<.send@http://127.0.0.1:8000/mootools.js:5706:13wrap/wrapper<@http://127.0.0.1:8000/smootools.js:1646:22Request<.initialize/this.send@http://127.0.0.1:8000/mootools.js:9997:18ReqJSON.send" }

I did try catch to pass the test error free for now. Thanks in advance 👍

swhiteman commented 5 years ago

Please show the code you're using that's "attempting XMLHttpRequest". You've only shown the exception.

What resource are you trying to get/head/post? Is it on the same origin as your main document?

mrf345 commented 5 years ago

@swhiteman Thanks for the prompt replay 👍 I don't get the whole picture myself, but the general idea is: I have a huge model that contains a time-out function that handles updating items, so it will make the XMLHttpRequest then updates the items:

toggleItems: function () {
    var self = this;
    if (gotTimedOut) clearTimeout(gotTimedOut)
    gotTimedOut = setTimeout(function () {
        self.retrieveItems(self.filterItems(self))
        // retrieveItems will do the XMLHttpRequest with req-json and sort out the items
    })
}
retrieveItems: function (filteredItems) {
    // do some sorting of existing items
    var req = new ReqJSON({
            'async': false,
            'url': window.location + 'someEndPoint',
            'onSuccess': callback
    }).send(JSON.encode(theDataToSubmit))
    // do some more filtering
}

The exception showed before leads to this chunk of mootools.js:

this.fireEvent('request');
xhr.send(data);
if (!this.options.async) this.onStateChange();
if (this.options.timeout) this.timer = this.timeout.delay(this.options.timeout, this);
return this;

Interesting warning message i got from mootools.js before the exceptions was raised:

Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help http://xhr.spec.whatwg.org/

While debugging i tried to resend the data and got this exception:

[Exception... "Component not initialized"  nsresult: "0xc1f30001 (NS_ERROR_NOT_INITIALIZED)"  location: "JS frame :: debugger eval code :: <TOP_LEVEL> :: line 1"  data: no]
swhiteman commented 5 years ago

But you still haven't included the relevant information about the main document's origin and the XHR destination's origin.

The common sync XHR warning does not itself stop a request from going out but that doesn't mean a CORS response can be processed.

mrf345 commented 5 years ago

My bad, i'm trying to post on the same origin. the request stoped and the first exception got raised.

swhiteman commented 5 years ago

Do you have a live repro of this problem (CodePen, jsFiddle, et al.)?

mrf345 commented 5 years ago

No i don't. I've encountered it during E2E testing on a local dev environment.

swhiteman commented 5 years ago

I guess you'll have to work toward a public repro case.

Curious if you get the same result with the well-known port for HTTP (TCP 80). What about with GET? And are you absolutely sure the XHR is being sent to the same origin (protocol + hostname + port)?

mrf345 commented 5 years ago

I will try setting up one later. I'm sure of the same origin as it is attempting to post to window.location.href + .... Good idea i'll try get instead, and try running the test on chrome too.

Thanks a lot @swhiteman

mrf345 commented 5 years ago

Turns out it was an authentication issue with the post request. Thanks, and sorry for wasting your time @swhiteman .