file_multie10s_update.html (960B)
1 <html> 2 <body> 3 <script> 4 5 var bc = new BroadcastChannel('start'); 6 bc.onmessage = function(e) { 7 // This message is not for us. 8 if (e.data != 'go') { 9 return; 10 } 11 12 // It can happen that we don't have the registrations yet. Let's try with a 13 // timeout. 14 function proceed() { 15 return navigator.serviceWorker.getRegistrations().then(regs => { 16 if (!regs.length) { 17 setTimeout(proceed, 200); 18 return; 19 } 20 21 bc = new BroadcastChannel('result'); 22 regs[0].update().then(() => { 23 bc.postMessage(0); 24 }, () => { 25 bc.postMessage(1); 26 }); 27 28 // Tell the coordinating frame script that we've kicked off our update 29 // call so that the SW script can be released once both instances of us 30 // have triggered update() and 1 has failed. 31 const blockingChannel = new BroadcastChannel('update'); 32 blockingChannel.postMessage(true); 33 }); 34 } 35 36 proceed(); 37 } 38 </script> 39 </body> 40 </html>