Просмотр исходного кода

Fix Safari camera stream failing with Service Worker error

Camera streams on macOS Safari were failing with "FetchEvent.respondWith
received an error: Load failed" because the Service Worker was intercepting
MJPEG streaming responses. Safari has known issues handling continuous
streaming responses through Service Workers.

- Add exclusion for /camera/stream and /camera/snapshot URLs in SW fetch handler
- Bump cache version to v24 to force SW update on clients

The camera components already have robust error handling with reconnect logic,
so bypassing the SW for these endpoints is safe and improves performance.
maziggy 7 месяцев назад
Родитель
Сommit
2cac34795e
2 измененных файлов с 14 добавлено и 4 удалено
  1. 7 2
      frontend/public/sw.js
  2. 7 2
      static/sw.js

+ 7 - 2
frontend/public/sw.js

@@ -1,6 +1,6 @@
 // Bambuddy Service Worker
 // Bambuddy Service Worker
-const CACHE_NAME = 'bambuddy-v23';
-const STATIC_CACHE = 'bambuddy-static-v23';
+const CACHE_NAME = 'bambuddy-v24';
+const STATIC_CACHE = 'bambuddy-static-v24';
 
 
 // Static assets to cache on install
 // Static assets to cache on install
 const STATIC_ASSETS = [
 const STATIC_ASSETS = [
@@ -62,6 +62,11 @@ self.addEventListener('fetch', (event) => {
     return;
     return;
   }
   }
 
 
+  // Skip camera stream/snapshot requests - Safari has issues with streaming through SW
+  if (url.pathname.includes('/camera/stream') || url.pathname.includes('/camera/snapshot')) {
+    return;
+  }
+
   // API requests - network first, no cache (real-time data is critical)
   // API requests - network first, no cache (real-time data is critical)
   if (url.pathname.startsWith('/api/')) {
   if (url.pathname.startsWith('/api/')) {
     event.respondWith(
     event.respondWith(

+ 7 - 2
static/sw.js

@@ -1,6 +1,6 @@
 // Bambuddy Service Worker
 // Bambuddy Service Worker
-const CACHE_NAME = 'bambuddy-v23';
-const STATIC_CACHE = 'bambuddy-static-v23';
+const CACHE_NAME = 'bambuddy-v24';
+const STATIC_CACHE = 'bambuddy-static-v24';
 
 
 // Static assets to cache on install
 // Static assets to cache on install
 const STATIC_ASSETS = [
 const STATIC_ASSETS = [
@@ -62,6 +62,11 @@ self.addEventListener('fetch', (event) => {
     return;
     return;
   }
   }
 
 
+  // Skip camera stream/snapshot requests - Safari has issues with streaming through SW
+  if (url.pathname.includes('/camera/stream') || url.pathname.includes('/camera/snapshot')) {
+    return;
+  }
+
   // API requests - network first, no cache (real-time data is critical)
   // API requests - network first, no cache (real-time data is critical)
   if (url.pathname.startsWith('/api/')) {
   if (url.pathname.startsWith('/api/')) {
     event.respondWith(
     event.respondWith(