Page 1 of 1

Strange behaviour of xmlhttprequest

Posted: 2018-05-27, 14:25
by thosrtanner
This snippet:

Code: Select all

    const url = "http://rawrtacular.com/bataneart/";
    const xmlHttpRequest = new XMLHttpRequest();
    xmlHttpRequest.open("GET", url);
    xmlHttpRequest.ontimeout = evt => { console.log("timed out", evt, url) };
    xmlHttpRequest.onabort = evt => { console.log("aborted", evt, url) };
    xmlHttpRequest.onerror = evt => { console.log("error", evt, url) };
    xmlHttpRequest.onload = evt => { console.log("complete", evt, url) };
    xmlHttpRequest.timeout = 10000;
    xmlHttpRequest.send();
works absolutely fine. But replace the url with "http://rawrtacular.com/bataneart" - and the request times out. Typing the url in the browser window without the '/' at the end works fine. Having said which it grows a trailing / in the process and the console says this:

Code: Select all

GET http://rawrtacular.com/bataneart [HTTP/1.1 301 Moved Permanently 250ms]
GET http://rawrtacular.com/bataneart/ [HTTP/1.1 200 OK 250ms]
so maybe the question should be why my XMLHttpRequest isn't behaving the same as the browser, and what should I do?

Addendum: I looked at the value of evt in the timeout and it has had the '/' appended to the responseURL.

Re: Strange behaviour of xmlhttprequest

Posted: 2018-05-27, 15:02
by JustOff
I can't reproduce your issue, both urls work just fine:

Code: Select all

17:49:44.676 GET XHR http://rawrtacular.com/bataneart/ [HTTP/1.1 200 OK 1631ms]
17:49:46.280 "complete" load { target: XMLHttpRequest, isTrusted: true, lengthComputable: true, loaded: 28029, total: 28029, currentTarget: XMLHttpRequest, eventPhase: 2, bubbles: false, cancelable: false, defaultPrevented: false, timeStamp: 1527432586280000 } "http://rawrtacular.com/bataneart/" Scratchpad/1:7:37

17:50:01.663 GET XHR http://rawrtacular.com/bataneart [HTTP/1.1 301 Moved Permanently 309ms]
17:50:01.978 GET XHR http://rawrtacular.com/bataneart/ [HTTP/1.1 200 OK 305ms]
17:50:02.259 "complete" load { target: XMLHttpRequest, isTrusted: true, lengthComputable: true, loaded: 28029, total: 28029, currentTarget: XMLHttpRequest, eventPhase: 2, bubbles: false, cancelable: false, defaultPrevented: false, timeStamp: 1527432602259000 } "http://rawrtacular.com/bataneart"

Re: Strange behaviour of xmlhttprequest

Posted: 2018-05-27, 16:36
by thosrtanner
Oh great. it works consistently in the console but fails consistently in the context of my extension

Re: Strange behaviour of xmlhttprequest

Posted: 2018-05-27, 16:39
by JustOff
Just as a guess, try using var/let instead of const.

Re: Strange behaviour of xmlhttprequest

Posted: 2018-05-27, 16:42
by thosrtanner
no, broken in console. i'd put the wrong name in the request. once i'd fixed the name it times out still.

I had an issue a bit like this once that I think went away when I deleted places db, but that doesn't seem to have worked this time.

Addendum. It works in safe mode so sounds like 'hunt the extension" :-(

Re: Strange behaviour of xmlhttprequest

Posted: 2018-05-27, 17:03
by thosrtanner
and now I commit the sin of replying to myself. It's apparently adblock latitude that is doing this...

Re: Strange behaviour of xmlhttprequest

Posted: 2018-05-27, 17:05
by JustOff
Well ... you know ... :twisted:

Re: Strange behaviour of xmlhttprequest

Posted: 2018-05-27, 18:03
by thosrtanner
:-P Now what do I do about adblock latitude (printable answers only please!)

Re: Strange behaviour of xmlhttprequest

Posted: 2018-05-27, 18:13
by JustOff
Perhaps use a clean profile for development? :roll:

Re: Strange behaviour of xmlhttprequest

Posted: 2018-05-28, 21:23
by thosrtanner
It appears there's a rule that effectively blocks websites that are too short and don't end in a slash...