sw_storage_not_allow.js (1017B)
1 let clientId; 2 addEventListener("fetch", function (event) { 3 event.respondWith( 4 (async function () { 5 if (event.request.url.includes("getClients")) { 6 // Expected to fail since the storage access is not allowed. 7 try { 8 await self.clients.matchAll(); 9 } catch (e) { 10 // expected failure 11 } 12 } else if (event.request.url.includes("getClient-stage1")) { 13 let clients = await self.clients.matchAll(); 14 clientId = clients[0].id; 15 } else if (event.request.url.includes("getClient-stage2")) { 16 // Expected to fail since the storage access is not allowed. 17 try { 18 await self.clients.get(clientId); 19 } catch (e) { 20 // expected failure 21 } 22 } 23 24 // Pass through the network request once our various Clients API 25 // promises have completed. 26 return await fetch(event.request); 27 })() 28 ); 29 }); 30 31 addEventListener("activate", function (event) { 32 event.waitUntil(clients.claim()); 33 });