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