From be7157b62cfe3ce326db0676012f97f4c89d0d3d Mon Sep 17 00:00:00 2001 From: "D. Berge" Date: Wed, 6 Aug 2025 10:45:05 +0200 Subject: [PATCH] Downgrade gracefully if window.caches is not available. This should not happen in production, as the Cache API is widely implemented as of the date of this commit, but it will not be available if the user is not in a secure context. That should only happen during testing. --- .../source/src/lib/deck.gl/DougalBinaryLoader.js | 2 +- .../source/src/store/modules/api/actions.js | 2 +- lib/www/client/source/src/views/Map.vue | 16 +++++++++------- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/www/client/source/src/lib/deck.gl/DougalBinaryLoader.js b/lib/www/client/source/src/lib/deck.gl/DougalBinaryLoader.js index 5fe08cc..3e5bd3b 100644 --- a/lib/www/client/source/src/lib/deck.gl/DougalBinaryLoader.js +++ b/lib/www/client/source/src/lib/deck.gl/DougalBinaryLoader.js @@ -19,7 +19,7 @@ async function cachedFetch(url, init, opts = {}) { } } - if (opts?.cache) { + if (opts?.cache && window.cache) { cache = await caches.open(opts.cache.name); res = await cache.match(url); isCached = !!res; diff --git a/lib/www/client/source/src/store/modules/api/actions.js b/lib/www/client/source/src/store/modules/api/actions.js index 49d2e0b..b291805 100644 --- a/lib/www/client/source/src/store/modules/api/actions.js +++ b/lib/www/client/source/src/store/modules/api/actions.js @@ -61,7 +61,7 @@ async function api ({state, getters, commit, dispatch}, [resource, init = {}, cb } } - if (opts?.cache) { + if (opts?.cache && window.caches) { cache = await caches.open(opts.cache.name); res = await cache.match(url); isCached = !!res; diff --git a/lib/www/client/source/src/views/Map.vue b/lib/www/client/source/src/views/Map.vue index 95da4a8..31b8cea 100644 --- a/lib/www/client/source/src/views/Map.vue +++ b/lib/www/client/source/src/views/Map.vue @@ -879,13 +879,15 @@ export default { }, async refresh () { - const cache = await caches.open("dougal"); - for (const key of await cache.keys()) { - // Match only resolved requests - if (key instanceof Request) { - if (key.url?.match(`/project/${this.$route.params.project}`)) { - console.log("removing", key.method, key.url); - cache.delete(key); + if (window.caches) { + const cache = await caches.open("dougal"); + for (const key of await cache.keys()) { + // Match only resolved requests + if (key instanceof Request) { + if (key.url?.match(`/project/${this.$route.params.project}`)) { + console.log("removing", key.method, key.url); + cache.delete(key); + } } } }