Skip to content

Instantly share code, notes, and snippets.

@snshn
Last active May 6, 2024 22:47
Show Gist options
  • Save snshn/a3f09016986abb04da16b80382f6adc5 to your computer and use it in GitHub Desktop.
Save snshn/a3f09016986abb04da16b80382f6adc5 to your computer and use it in GitHub Desktop.
// <script>
class myXMLHttpRequest extends XMLHttpRequest {
constructor() {
super();
this._open = this.open;
this.open = (method, target) => {
// TODO replace file: with http/https: here
console.warn(target);
var base = "https://gist.github.com/snshn/a3f09016986abb04da16b80382f6adc5";
return this._open(method, new URL(target, base));
}
}
}
XMLHttpRequest = myXMLHttpRequest;
// </script>
//////////////////////
// Proof of concept //
//////////////////////
var oReq = new XMLHttpRequest();
oReq.onload = function(e) {
var ab = oReq.response;
const decoder = new TextDecoder();
const str = decoder.decode(ab)
console.log(str);
}
oReq.open("GET", '/');
oReq.responseType = "arraybuffer";
oReq.send();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment