Skip to content

Commit f3755bf

Browse files
authored
Prevent manifest challenge pages from polluting service worker cache (#38)
* Fix dropdown option contrast in native menus Set explicit option and optgroup colors so dropdown items remain readable in light native popups while keeping dark themed select controls. * Fix manifest syntax and stale cache handling Simplify the web manifest to a strict, minimal valid payload and add an app id. Bump service worker cache version and only cache successful network responses to prevent stale HTML/error responses from breaking manifest parsing. * Prevent manifest challenge pages from polluting SW cache Exclude manifest requests from service worker handling, remove manifest from app-shell precache, and avoid caching HTML for non-document requests. Bump cache version to flush previously cached bad responses.
1 parent e23178d commit f3755bf

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

celstomp/service-worker.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const CACHE_VERSION = "celstomp-v6";
1+
const CACHE_VERSION = "celstomp-v7";
22

3-
const APP_SHELL = [ "./", "./index.html", "./celstomp-styles.css", "./celstomp-imgseq.js", "./celstomp-autosave.js", "./celstomp-app.js", "./manifest.webmanifest", "./icons/favicon.ico" ];
3+
const APP_SHELL = [ "./", "./index.html", "./celstomp-styles.css", "./celstomp-imgseq.js", "./celstomp-autosave.js", "./celstomp-app.js", "./icons/favicon.ico" ];
44

55
self.addEventListener("install", event => {
66
event.waitUntil(caches.open(CACHE_VERSION).then(async c => {
@@ -18,12 +18,21 @@ self.addEventListener("fetch", event => {
1818
const req = event.request;
1919
const url = new URL(req.url);
2020
if (url.origin !== self.location.origin) return;
21+
22+
const isManifestRequest = req.destination === "manifest" || url.pathname.endsWith("/manifest.webmanifest");
23+
if (isManifestRequest) return;
24+
2125
event.respondWith(caches.match(req).then(cached => {
2226
if (cached) return cached;
2327
return fetch(req).then(res => {
2428
if (res.ok) {
25-
const copy = res.clone();
26-
caches.open(CACHE_VERSION).then(c => c.put(req, copy));
29+
const contentType = (res.headers.get("content-type") || "").toLowerCase();
30+
const isDocument = req.mode === "navigate" || req.destination === "document";
31+
const isHtml = contentType.includes("text/html");
32+
if (isDocument || !isHtml) {
33+
const copy = res.clone();
34+
caches.open(CACHE_VERSION).then(c => c.put(req, copy));
35+
}
2736
}
2837
return res;
2938
}).catch(() => {

0 commit comments

Comments
 (0)