1/* Manabu Neko â navigate-only guard for Next.js static-export RSC `.txt` URLs. 2 * 3 * Soft navigations fetch `*.txt` RSC payloads (must keep working). 4 * Full document navigations to those URLs make mobile Chrome download text/plain. 5 * Intercept only request.mode === "navigate" and send users to the HTML route. 6 */ 7const PASSTHROUGH = new Set(["/ads.txt", "/robots.txt"]); 8 9self.addEventListener("install", (event) => { 10 event.waitUntil(self.skipWaiting()); 11}); 12 13self.addEventListener("activate", (event) => { 14 event.waitUntil(self.clients.claim()); 15}); 16 17self.addEventListener("fetch", (event) => { 18 if (event.request.mode !== "navigate") return; 19 20 let url; 21 try { 22 url = new URL(event.request.url); 23 } catch { 24 return; 25 } 26 27 if (url.origin !== self.location.origin) return; 28 if (!url.pathname.endsWith(".txt")) return; 29 if (PASSTHROUGH.has(url.pathname)) return; 30 31 let path = url.pathname.slice(0, -".txt".length); 32 if (path.endsWith("/index")) { 33 path = path.slice(0, -"/index".length) || "/"; 34 } 35 36 const nextMarker = path.indexOf("/__next."); 37 if (nextMarker !== -1) { 38 path = path.slice(0, nextMarker) || "/"; 39 } 40 41 if (!path) path = "/"; 42 43 const dest = `${path}${url.search}${url.hash}`; 44 event.respondWith(Response.redirect(new URL(dest, url.origin), 302)); 45});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.