self.addEventListener("install", () => {
  self.skipWaiting();
});

self.addEventListener("activate", (event) => {
  event.waitUntil(
    (async () => {
      await self.clients.claim();
      const windows = await self.clients.matchAll({ type: "window", includeUncontrolled: true });
      await Promise.all(
        windows.map(async (client) => {
          try {
            await client.navigate(client.url);
          } catch {
            // The client may have closed while the new worker was activating.
          }
        })
      );
    })()
  );
});

self.addEventListener("fetch", (event) => {
  if (event.request.mode !== "navigate") return;
  event.respondWith(fetch(new Request(event.request, { cache: "no-store" })));
});
