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
All checks were successful
Build MIPS Binary / build (push) Successful in 1m57s
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
const CACHE_NAME = "vibetorrent-v2";
|
const CACHE_NAME = "vibetorrent-v3";
|
||||||
const ASSETS_TO_CACHE = [
|
const ASSETS_TO_CACHE = [
|
||||||
"/",
|
"/",
|
||||||
"/index.html",
|
"/index.html",
|
||||||
@@ -51,6 +51,11 @@ self.addEventListener("activate", (event) => {
|
|||||||
self.addEventListener("fetch", (event) => {
|
self.addEventListener("fetch", (event) => {
|
||||||
const url = new URL(event.request.url);
|
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
|
// Network-first strategy for API calls
|
||||||
if (url.pathname.startsWith("/api/")) {
|
if (url.pathname.startsWith("/api/")) {
|
||||||
event.respondWith(
|
event.respondWith(
|
||||||
@@ -75,10 +80,12 @@ self.addEventListener("fetch", (event) => {
|
|||||||
fetch(event.request)
|
fetch(event.request)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
// Cache the latest version of the HTML
|
// Cache the latest version of the HTML
|
||||||
const responseToCache = response.clone();
|
if (response && response.status === 200) {
|
||||||
caches.open(CACHE_NAME).then((cache) => {
|
const responseToCache = response.clone();
|
||||||
cache.put(event.request, responseToCache);
|
caches.open(CACHE_NAME).then((cache) => {
|
||||||
});
|
cache.put(event.request, responseToCache);
|
||||||
|
});
|
||||||
|
}
|
||||||
return response;
|
return response;
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user