Files
vue-cli/packages/@vue/cli-plugin-pwa/lib/noopServiceWorker.js
Jakub Niewczas ffc0686e89 fix: fix pwa installability by adding fetch event listener to noopServiceWorker (#5327)
currently google chrome prevents installing pwa due to the error: “Page does not work offline”. The reason is service worker has to listen to fetch event. It doesnt have to do anything so the listener can be an empty function, but it has to be declared
2021-01-06 12:28:17 +08:00

26 lines
902 B
JavaScript

/* eslint-disable-next-line no-redeclare */
/* global self */
// This service worker file is effectively a 'no-op' that will reset any
// previous service worker registered for the same host:port combination.
// It is read and returned by a dev server middleware that is only loaded
// during development.
// In the production build, this file is replaced with an actual service worker
// file that will precache your site's local assets.
self.addEventListener('install', () => self.skipWaiting())
self.addEventListener('fetch', () => {})
self.addEventListener('activate', () => {
self.clients.matchAll({ type: 'window' }).then(windowClients => {
for (const windowClient of windowClients) {
// Force open pages to refresh, so that they have a chance to load the
// fresh navigation response from the local dev server.
windowClient.navigate(windowClient.url)
}
})
})