fix(ui): fix service worker crashes for chrome extensions and bump cache version
All checks were successful
Build MIPS Binary / build (push) Successful in 1m57s

This commit is contained in:
spinline
2026-02-21 00:25:28 +03:00
parent f8639f2967
commit d88084fb9a

View File

@@ -1,4 +1,4 @@
const CACHE_NAME = "vibetorrent-v2";
const CACHE_NAME = "vibetorrent-v3";
const ASSETS_TO_CACHE = [
"/",
"/index.html",
@@ -51,6 +51,11 @@ self.addEventListener("activate", (event) => {
self.addEventListener("fetch", (event) => {
const url = new URL(event.request.url);
// Skip unsupported schemes (like chrome-extension://)
if (!url.protocol.startsWith("http")) {
return;
}
// Network-first strategy for API calls
if (url.pathname.startsWith("/api/")) {
event.respondWith(
@@ -75,10 +80,12 @@ self.addEventListener("fetch", (event) => {
fetch(event.request)
.then((response) => {
// Cache the latest version of the HTML
if (response && response.status === 200) {
const responseToCache = response.clone();
caches.open(CACHE_NAME).then((cache) => {
cache.put(event.request, responseToCache);
});
}
return response;
})
.catch(() => {