From b9cb33e36def0ac46dc4653bd155472e116d5537 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 6 Jan 2026 20:04:06 +0000 Subject: [PATCH] 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. --- js/app.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/js/app.js b/js/app.js index 12539648..7686c6e1 100644 --- a/js/app.js +++ b/js/app.js @@ -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); }