feat: add plugin to unregister existing service workers on client
All checks were successful
Build And Push Image / docker (push) Successful in 2m51s
All checks were successful
Build And Push Image / docker (push) Successful in 2m51s
This commit is contained in:
19
plugins/02.unregister-sw.client.ts
Normal file
19
plugins/02.unregister-sw.client.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
// Plugin to unregister any existing service workers
|
||||
export default defineNuxtPlugin(async () => {
|
||||
if (process.client && 'serviceWorker' in navigator) {
|
||||
try {
|
||||
const registrations = await navigator.serviceWorker.getRegistrations();
|
||||
|
||||
for (const registration of registrations) {
|
||||
console.log('🧹 Unregistering service worker:', registration.scope);
|
||||
await registration.unregister();
|
||||
}
|
||||
|
||||
if (registrations.length > 0) {
|
||||
console.log('✅ All service workers unregistered');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('❌ Error unregistering service workers:', error);
|
||||
}
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user