Skip to content

Commit

Permalink
feat(shell): add killswitch service worker (#583)
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiVandivier committed Jul 2, 2021
1 parent 21ece74 commit 1ba1c1e
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions shell/public/service-worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* eslint-disable no-restricted-globals */

// A simple, no-op service worker that takes immediate control and tears
// everything down; has no fetch handler. Fixes apps with rogue service workers
self.addEventListener('install', () => {
self.skipWaiting()
})

self.addEventListener('activate', async () => {
console.log('Removing previous service worker')
// Unregister, in case app doesn't
self.registration.unregister()
// Delete all caches
const keys = await self.caches.keys()
await Promise.all(keys.map(key => self.caches.delete(key)))
// Force refresh all windows
const clients = await self.clients.matchAll({ type: 'window' })
clients.forEach(client => client.navigate(client.url))
})

0 comments on commit 1ba1c1e

Please sign in to comment.