I'm working on a game engine which can work either under nw.js or under a browser. In a browser, XMLHttpRequest returns status = 200 for a successful request. However, in nw.js it returns 0 (because there's no timeout when you load a local file, duh).
My game engine uses external libraries which are, apart from minified, unable to be edited by myself (or any other user of my game engine, for that matter) due to obvious reasons. My idea is to override "onreadystatechange" and, if I receive a status = 0, change it with status = 200 if running under nw.js.
I've tried this, but status keeps being zero:
(function(xhr) {
var send = xhr.send;
xhr.send = function(data) {
var rsc = this.onreadystatechange;
if (rsc) {
this.onreadystatechange = function() {
if(this.readyState == 4)
if(this.status == 0)
this.status = 200;
return rsc.apply(this, arguments);
};
}
return send.apply(this, arguments);
};
})(XMLHttpRequest.prototype);
This is taken from Rob W's excellent answer found here. I've also read in the MDN that the status variable is read-only. Is there any way to override that? Thanks in advance :).