| OLD | NEW |
| (Empty) |
| 1 importScripts('fetch-test-options.js'); | |
| 2 importScripts('fetch-access-control-util.js'); | |
| 3 | |
| 4 var port = undefined; | |
| 5 var isTestTargetFetch = false; | |
| 6 | |
| 7 self.onmessage = function(e) { | |
| 8 var message = e.data; | |
| 9 if ('port' in message) { | |
| 10 port = message.port; | |
| 11 } else if (message.msg === 'START TEST CASE') { | |
| 12 isTestTargetFetch = true; | |
| 13 port.postMessage({msg: 'READY'}); | |
| 14 } | |
| 15 }; | |
| 16 | |
| 17 self.addEventListener('fetch', function(event) { | |
| 18 if (!isTestTargetFetch) { | |
| 19 // Don't handle the event when it is not the test target fetch such as a | |
| 20 // redirected fetch or for the iframe html. | |
| 21 return; | |
| 22 } | |
| 23 isTestTargetFetch = false; | |
| 24 | |
| 25 event.respondWith( | |
| 26 doFetch(event.request) | |
| 27 .then(function(message) { | |
| 28 var response = message.response; | |
| 29 message.response = undefined; | |
| 30 // Send the result to fetch-access-control-util.js. | |
| 31 port.postMessage(message); | |
| 32 return response; | |
| 33 }) | |
| 34 .catch(function(message) { | |
| 35 port.postMessage(message); | |
| 36 return Promise.reject(); | |
| 37 }) | |
| 38 ); | |
| 39 }); | |
| OLD | NEW |