OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <title>Service Worker: frame for getRegistrations()</title> | 2 <title>Service Worker: frame for getRegistrations()</title> |
3 <script> | 3 <script> |
4 var scope = 'scope-for-getregistrations'; | 4 var scope = 'scope-for-getregistrations'; |
5 var script = 'empty-worker.js'; | 5 var script = 'empty-worker.js'; |
6 var registration; | 6 var registration; |
7 var port; | 7 var port; |
8 | 8 |
9 self.onmessage = function(e) { | 9 self.onmessage = function(e) { |
10 if (e.data == 'register') { | 10 if (e.data == 'register') { |
11 port = e.ports[0]; | 11 port = e.ports[0]; |
12 port.onmessage = function(e) { | 12 port.onmessage = function(e) { |
13 if (e.data == 'unregister') { | 13 if (e.data == 'unregister') { |
14 registration.unregister() | 14 registration.unregister() |
15 .then(function() { | 15 .then(function() { |
16 port.postMessage('unregistered'); | 16 port.postMessage('unregistered'); |
17 }); | 17 }); |
18 } | 18 } |
19 }; | 19 }; |
20 } | 20 } |
21 | 21 |
22 // Frame registers a registration scoped | 22 // Frame registers a registration scoped |
23 // http://localhost:8000/serviceworker/resources/scope-for-getregistrations | 23 // (origin)/serviceworker/resources/scope-for-getregistrations |
24 navigator.serviceWorker.register(script, { scope: scope }) | 24 navigator.serviceWorker.register(script, { scope: scope }) |
25 .then(function(r) { | 25 .then(function(r) { |
26 registration = r; | 26 registration = r; |
27 e.ports[0].postMessage('registered'); | 27 e.ports[0].postMessage('registered'); |
28 }); | 28 }); |
29 }; | 29 }; |
30 </script> | 30 </script> |
OLD | NEW |