Skip to content

Commit

Permalink
unregister old service worker
Browse files Browse the repository at this point in the history
  • Loading branch information
Paulchen-Panther committed Apr 5, 2024
1 parent 0d816ec commit b092864
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion docs/.vitepress/theme/components/ExtendedLayout.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { useData } from 'vitepress'
import DefaultTheme from 'vitepress/theme'
import { nextTick, provide } from 'vue'
import { nextTick, provide, onMounted } from 'vue'
import NotFound from './NotFound.vue'
import Annoucement from './Annoucement.vue'
Expand Down Expand Up @@ -40,6 +40,27 @@ provide('toggle-appearance', async ({ clientX: x, clientY: y }: MouseEvent) => {
}
)
})
async function removeOldServiceWorker() {
try {
if (window.navigator && navigator.serviceWorker) {
navigator.serviceWorker.getRegistrations()
.then((registrations) => {
for (const registration of registrations) {
registration.unregister()
}
})
}
}
catch (error) {
console.error('Failed to remove service worker.')
console.error(error)
}
}
onMounted(() => {
removeOldServiceWorker();
})
</script>

<template>
Expand Down

0 comments on commit b092864

Please sign in to comment.