From 08d2f697203f629536a8c4b211f30ebaa7accb81 Mon Sep 17 00:00:00 2001 From: Honey Date: Sat, 25 Apr 2026 18:17:47 +0200 Subject: [PATCH] fix: SW must not intercept cross-origin requests (backend API calls) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added same-origin check so the SW only caches its own static assets. Cross-origin requests (Navidrome API, NovaSonic backend) pass through directly — SW interference was causing 'failed to fetch' in the PWA. Co-Authored-By: Claude Sonnet 4.6 --- sw.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sw.js b/sw.js index 52b91d0..67d1049 100644 --- a/sw.js +++ b/sw.js @@ -1,6 +1,6 @@ -const CACHE = 'ns-v23'; +const CACHE = 'ns-v24'; const PRECACHE = ['/', 'index.html', 'styles.css', 'app.js', 'manifest.json', 'icon.svg']; -const SKIP_URLS = ['/rest/stream', '/rest/download', '/config.js']; +const SKIP_PATHS = ['/rest/stream', '/rest/download', '/config.js']; self.addEventListener('install', e => { e.waitUntil(caches.open(CACHE).then(c => c.addAll(PRECACHE))); @@ -18,7 +18,8 @@ self.addEventListener('activate', e => { }); self.addEventListener('fetch', e => { - if (SKIP_URLS.some(u => e.request.url.includes(u))) return; + if (!e.request.url.startsWith(self.location.origin)) return; + if (SKIP_PATHS.some(p => e.request.url.includes(p))) return; e.respondWith( fetch(e.request) .then(res => {