sw_formSubmission.js (1142B)
1 /** 2 * We are used by test_formSubmission.html to immediately activate and start 3 * controlling its page. We operate in 3 modes, conveyed via ?MODE appended to 4 * our URL. 5 * 6 * - "no-fetch": Don't register a fetch listener so that the optimized fetch 7 * event bypass happens. 8 * - "reset-fetch": Do register a fetch listener, reset every interception. 9 * - "proxy-fetch": Do register a fetch listener, resolve every interception 10 * with fetch(event.request). 11 */ 12 13 const mode = location.search.slice(1); 14 15 // Fetch handling. 16 if (mode !== "no-fetch") { 17 addEventListener("fetch", function (event) { 18 if (mode === "reset-fetch") { 19 // Don't invoke respondWith, resetting the interception. 20 return; 21 } 22 if (mode === "proxy-fetch") { 23 // Per the spec, there's an automatic waitUntil() on this too. 24 event.respondWith(fetch(event.request)); 25 } 26 }); 27 } 28 29 // Go straight to activation, bypassing waiting. 30 addEventListener("install", function (event) { 31 event.waitUntil(skipWaiting()); 32 }); 33 // Control the test document ASAP. 34 addEventListener("activate", function (event) { 35 event.waitUntil(clients.claim()); 36 });