Strange behaviour of xmlhttprequest

Add-ons for Pale Moon and other applications
General discussion, compatibility, contributed extensions, themes, plugins, and more.

Moderators: FranklinDM, Lootyhoof

thosrtanner
Lunatic
Lunatic
Posts: 395
Joined: 2014-05-10, 18:19
Location: UK

Strange behaviour of xmlhttprequest

Unread post by thosrtanner » 2018-10-20, 15:41

I've come across a problem with xmlhttprequest which appears not to be obeying 301 redirects properly when the site is redirecting to https. For instance if I use xmlhttprequest to get http://barbarianprincess.com/feed/ the get eventually fails with a timeout but the target url has been updated correctly.

If I type that into the address bar, it redirects fine.

This is only happening on a couple of sites.

Addendum - this seems to be unrelated to it being http->https redirection. For instance, the 301 redirection of this url http://slightlyofftopic.com/?feed=rss2 always seems to time out in xmlhttprequest but not in the browser
Last edited by thosrtanner on 2018-10-20, 18:33, edited 1 time in total.

JustOff

Re: Strange behaviour of xmlhttprequest

Unread post by JustOff » 2018-10-20, 19:37

I guess you hit the CORS restrictions. Try to set mozSystem=true or use privileged XMLHttpRequest:

Code: Select all

let privXMLHttpRequest = Components.Constructor("@mozilla.org/xmlextras/xmlhttprequest;1","nsIXMLHttpRequest");
let request = new privXMLHttpRequest();

thosrtanner
Lunatic
Lunatic
Posts: 395
Joined: 2014-05-10, 18:19
Location: UK

Re: Strange behaviour of xmlhttprequest

Unread post by thosrtanner » 2018-10-20, 20:50

other ones seem to work fine. and it shouldn't be subject to CORS should it as its from an addon running in the main j/s context.

thosrtanner
Lunatic
Lunatic
Posts: 395
Joined: 2014-05-10, 18:19
Location: UK

Re: Strange behaviour of xmlhttprequest

Unread post by thosrtanner » 2018-11-06, 07:05

This problem happens with another site, where "http://drmcninja.com/feed" is redirected to "http://drmcninja.com/feed/". So it's the same site. In the console you see the 301 response but then the request times out. I'm not sure how that could trigger CORS. However it does appear to be doing so for random sites, as changing the request to a privileged request works.

This is only happening with xmlhttprequests for some sites where viewing in the browser window works fine. Hacking the url in the request also works fine, but that's not really a scalable solution. I think this may be a regression from v27 as I'm fairly sure it used to work fine. (Not that I have a v27 to test this assertion on any more).
Last edited by thosrtanner on 2018-11-06, 07:09, edited 1 time in total.

JustOff

Re: Strange behaviour of xmlhttprequest

Unread post by JustOff » 2018-11-06, 09:25

I can't reproduce your problem using Scratchpad, can you?

thosrtanner
Lunatic
Lunatic
Posts: 395
Joined: 2014-05-10, 18:19
Location: UK

Re: Strange behaviour of xmlhttprequest

Unread post by thosrtanner » 2018-11-06, 12:25

No, it works fine in scratchpad (once I put it into browser context. it gets upset in the other context)

Locked