Bug 1884032 [wpt PR 44942] - [css-color] add missing colorscheme-aware tests, a=testonly
[gecko.git] / dom / serviceworkers / test / sw_with_navigationPreload.js
blobafd7181dcfcc9a5532314bb827506abb53926468
1 addEventListener("activate", event => {
2   event.waitUntil(self.registration.navigationPreload.enable());
3 });
5 async function post_to_page(data) {
6   let cs = await self.clients.matchAll();
7   for (const client of cs) {
8     client.postMessage(data);
9   }
12 addEventListener("fetch", event => {
13   if (event.request.url.includes("navigationPreload_page.html")) {
14     event.respondWith(
15       new Response("<!DOCTYPE html>", {
16         headers: { "Content-Type": "text/html; charset=utf-8" },
17       })
18     );
20     event.waitUntil(
21       (async function () {
22         let preloadResponse = await event.preloadResponse;
23         let text = await preloadResponse.text();
24         await post_to_page(text);
25       })()
26     );
27   }
28 });