partitioned-service-worker-third-party-iframe.html (1230B)
1 <!DOCTYPE html> 2 <title>Service Worker: 3P iframe for partitioned service workers</title> 3 <script src="./test-helpers.sub.js"></script> 4 <script src="/common/get-host-info.sub.js"></script> 5 <script src="./partitioned-utils.js"></script> 6 7 8 <body> 9 This iframe will register a service worker when it loads and then add its own 10 iframe that will attempt to navigate to a url that service worker will intercept 11 and use to resolve the service worker's internal Promise. 12 <script> 13 14 async function onLoad() { 15 await setupServiceWorker(); 16 17 // When the SW's iframe finishes it'll post a message. This forwards it up to 18 // the window. 19 self.addEventListener('message', evt => { 20 window.parent.postMessage(evt.data, '*'); 21 }); 22 23 // Now try to resolve the SW's promise. If we're partitioned then there 24 // shouldn't be a promise to resolve. 25 const resolve_frame_url = new URL('./partitioned-resolve.fakehtml?From3pFrame', self.location); 26 const frame_resolve = await new Promise(resolve => { 27 var frame = document.createElement('iframe'); 28 frame.src = resolve_frame_url; 29 frame.onload = function() { resolve(frame); }; 30 document.body.appendChild(frame); 31 }); 32 } 33 34 self.addEventListener('load', onLoad); 35 </script> 36 </body>