| OLD | NEW |
| (Empty) |
| 1 <!DOCTYPE html> | |
| 2 <script src="../../resources/get-host-info.js?pipe=sub"></script> | |
| 3 <script src="test-helpers.js"></script> | |
| 4 <script> | |
| 5 var SCOPE = './navigation-redirect-to-http.php'; | |
| 6 var SCRIPT = 'navigation-redirect-to-http-worker.js'; | |
| 7 var host_info = get_host_info(); | |
| 8 | |
| 9 navigator.serviceWorker.getRegistration(SCOPE) | |
| 10 .then(function(registration) { | |
| 11 if (registration) | |
| 12 return registration.unregister(); | |
| 13 }) | |
| 14 .then(function() { | |
| 15 return navigator.serviceWorker.register(SCRIPT, {scope: SCOPE}); | |
| 16 }) | |
| 17 .then(function(registration) { | |
| 18 return new Promise(function(resolve) { | |
| 19 registration.addEventListener('updatefound', function() { | |
| 20 resolve(registration.installing); | |
| 21 }); | |
| 22 }); | |
| 23 }) | |
| 24 .then(function(worker) { | |
| 25 worker.addEventListener('statechange', on_state_change); | |
| 26 }) | |
| 27 .catch(function(reason) { | |
| 28 window.parent.postMessage({results: 'FAILURE: ' + reason.message}, | |
| 29 host_info['HTTP_ORIGIN']); | |
| 30 }); | |
| 31 | |
| 32 function on_state_change(event) { | |
| 33 if (event.target.state != 'activated') | |
| 34 return; | |
| 35 with_iframe(SCOPE, {auto_remove: false}) | |
| 36 .then(function(frame) { | |
| 37 window.parent.postMessage( | |
| 38 {results: frame.contentDocument.body.textContent}, | |
| 39 host_info['HTTP_ORIGIN']); | |
| 40 }); | |
| 41 } | |
| 42 | |
| 43 </script> | |
| OLD | NEW |