Skip to content

Commit

Permalink
fix(portal): service worker uninstall (#359)
Browse files Browse the repository at this point in the history
Signed-off-by: giac-mysten <[email protected]>
Co-authored-by: Alexandros Tzimas <[email protected]>
  • Loading branch information
giac-mysten and Tzal3x authored Jan 17, 2025
1 parent 1f42d78 commit e7d0326
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions portal/server/public/walrus-sites-sw.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

if ("serviceWorker" in navigator) {
navigator.serviceWorker
.getRegistrations()
.then(function (registrations) {
registrations.forEach(function (registration) {
registration.unregister();
});
})
.catch(function (error) {
console.error("Error unregistering service workers:", error);
});
}
// Inspired by https://github.com/NekR/self-destroying-sw
self.addEventListener("install", (_event) => {
self.skipWaiting();
});

self.addEventListener("activate", (_event) => {
self.registration
.unregister()
.then(() => self.clients.matchAll())
.then((clients) => {
clients.forEach((client) => {
if (client.url && "navigate" in client) {
client.navigate(client.url);
}
});
});
});

0 comments on commit e7d0326

Please sign in to comment.