blob: 2c80f25a3db2831f4b1e5633a455481d7a35b4c7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
self.onmessage = function (evt) {
if (evt.data == "xhr") {
var xhr = new XMLHttpRequest();
xhr.open("GET", "synthesized-response.txt", true);
xhr.responseType = "text";
xhr.send();
xhr.onload = function (evt) {
postMessage(xhr.responseText);
};
xhr.onerror = function() {
postMessage("XHR failed!");
};
} else if (evt.data == "fetch") {
fetch("synthesized-response.txt")
.then(function(response) {
return response.text();
})
.then(function(data) {
postMessage(data);
})
.catch(function(error) {
postMessage("Fetch failed!");
});
} else if (evt.data == "importScripts") {
importScripts("synthesized-response.js");
} else {
throw "Unexpected message! " + evt.data;
}
};
|