handle when navigator controller isn't present

This commit is contained in:
keyan 2023-08-08 16:55:08 -05:00
parent 3cfeede46a
commit da78d244ef
2 changed files with 2 additions and 4 deletions

View File

@ -99,7 +99,7 @@ export const ServiceWorkerProvider = ({ children }) => {
// since (a lot of) browsers don't support the pushsubscriptionchange event,
// we sync with server manually by checking on every page reload if the push subscription changed.
// see https://medium.com/@madridserginho/how-to-handle-webpush-api-pushsubscriptionchange-event-in-modern-browsers-6e47840d756f
navigator.serviceWorker.controller.postMessage({ action: 'SYNC_SUBSCRIPTION' })
navigator?.serviceWorker?.controller?.postMessage?.({ action: 'SYNC_SUBSCRIPTION' })
}, [])
useEffect(() => {

View File

@ -7,6 +7,7 @@ import { enable } from 'workbox-navigation-preload'
import manifest from './precache-manifest.json'
import ServiceWorkerStorage from 'serviceworker-storage'
// comment out to enable workbox console logs
self.__WB_DISABLE_DEV_LOGS = true
const storage = new ServiceWorkerStorage('sw:storage', 1)
@ -15,9 +16,6 @@ const storage = new ServiceWorkerStorage('sw:storage', 1)
// https://developer.chrome.com/docs/workbox/modules/workbox-navigation-preload/
enable()
// uncomment to disable workbox console logs
// self.__WB_DISABLE_DEV_LOGS = true
// ignore precache manifest generated by InjectManifest
// they statically check for the presence of this variable
console.log(self.__WB_MANIFEST)