Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(shell): add killswitch service worker #583

Merged
merged 3 commits into from
Jul 2, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
})