Fix 404 error when cancelling service worker stream

Guards the `fetch("/webtorrent/cancel/")` call in `js/app.js` with a check for `navigator.serviceWorker.controller` and adds a `try...catch` block. This prevents the application from making a network request to a virtual route that doesn't exist on the server when the Service Worker is not active or controlling the page, eliminating "404 Not Found" errors in the console during cleanup.
This commit is contained in:
google-labs-jules[bot] committed 2026-01-06 20:04:06 +00:00
1 parent b6e9b39639
commit b9cb33e36d
1 file changed
+11 -1
+11 -1
View File
@@ -4260,6 +4260,14 @@ class Application {
// Tell webtorrent to cleanup
await torrentClient.cleanup();
this.log("[cleanup] WebTorrent cleanup resolved.");
try {
if (navigator.serviceWorker && navigator.serviceWorker.controller) {
await fetch("/webtorrent/cancel/", { mode: "no-cors" });
}
} catch (err) {
// Ignore errors when cancelling the service worker stream; it may not be active.
}
} catch (err) {
devLogger.error("Cleanup error:", err);
} finally {
@@ -4895,7 +4903,9 @@ class Application {
// user-visible UI is already closed.
const performCleanup = async () => {
try {
await fetch("/webtorrent/cancel/", { mode: "no-cors" });
if (navigator.serviceWorker && navigator.serviceWorker.controller) {
await fetch("/webtorrent/cancel/", { mode: "no-cors" });
}
} catch (err) {
devLogger.warn("[hideModal] webtorrent cancel fetch failed:", err);
}