// A site's own worker at scope "/" that composes the runtime's, as // ServiceWorkerConflictError advises. Its own listeners run alongside the runtime's: // it serves one marker URL, which reports the events the site's listeners saw. importScripts("/dist/runtime/sw.js"); // Top-level names a site might use; the runtime's bundle must not collide with them. const seen = []; let b = "site"; self.addEventListener("install", () => seen.push("install")); self.addEventListener("activate", () => seen.push("activate")); self.addEventListener("message", (e) => { if (e.data?.t === "site-hello") seen.push("message"); }); self.addEventListener("fetch", (e) => { if (new URL(e.request.url).pathname !== "/tests/fixtures/compose/marker") return; e.respondWith(new Response(JSON.stringify({ servedBy: b, seen }), { headers: { "Content-Type": "application/json", "Cross-Origin-Resource-Policy": "same-origin" }, })); });