mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-02 10:52:27 +00:00
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:
1 parent
b6e9b39639
commit
b9cb33e36d
1 file changed
+11
-1
@@ -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);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user