Created
July 29, 2019 00:53
-
-
Save sabitertan/af8abe2f9e738cd7189d2e1cf244e75b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| window.fetch = (url, info) => { | |
| return new Promise(function (resolve, reject) { | |
| let xhr = new XMLHttpRequest(); | |
| xhr.open(info.method || "GET", url); | |
| if (url.endsWith(".wasm")) | |
| xhr.responseType = "arraybuffer"; | |
| xhr.onload = function () { | |
| if (this.status >= 200 && this.status < 300) { | |
| resolve({ | |
| headers: xhr.getAllResponseHeaders().split("\r\n"), | |
| json: () => JSON.parse(xhr.response), | |
| ok: true, | |
| arrayBuffer: () => xhr.response, | |
| byteLenght: (new TextEncoder('utf-8').encode(xhr.response)).length | |
| }); | |
| } else { | |
| reject({ | |
| status: this.status, | |
| statusText: xhr.statusText | |
| }); | |
| } | |
| }; | |
| xhr.onerror = function () { | |
| reject({ | |
| status: this.status, | |
| statusText: xhr.statusText | |
| }); | |
| }; | |
| xhr.send(); | |
| }) | |
| }; | |
| WebAssembly.instantiateStreaming = undefined; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment