Source code

Revision control

Copy as Markdown

Other Tools

<!DOCTYPE html>
<title>Service Worker: 3P iframe for partitioned service workers</title>
<script src="./test-helpers.sub.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="./partitioned-utils.js"></script>
<body>
This iframe will register a service worker when it loads and then will use
getRegistrations to get a handle to the SW. It will then postMessage to the
SW to retrieve the SW's ID. This iframe will then forward that message up,
eventually, to the test.
<script>
async function onLoad() {
const scope = './partitioned-'
const absoluteScope = new URL(scope, window.location).href;
await setupServiceWorker();
// Once the SW sends us its ID, forward it up to the window.
navigator.serviceWorker.addEventListener('message', evt => {
window.parent.postMessage(evt.data, '*');
});
// Now get the SW with getRegistrations.
const retrieved_registrations =
await navigator.serviceWorker.getRegistrations();
// It's possible that other tests have left behind other service workers.
// This steps filters those other SWs out.
const filtered_registrations =
retrieved_registrations.filter(reg => reg.scope == absoluteScope);
filtered_registrations[0].active.postMessage({type: "get-id"});
}
self.addEventListener('load', onLoad);
</script>
</body>