Hi I have been trying to learn PWA and is having a problem with service workers, basically when I try to audit through lighthouse I get the following error:
Service Worker not registered: Failed to register a ServiceWorker for scope ('http://127.0.0.1:5500/') with script ('http://127.0.0.1:5500/sw.js')
Though when I start the app it says it has been activated and is running under the Application tab in devtools. The information I log to the console also show it as registered.
Edit: I'm logging the following information to the console if it helps.
ServiceWorkerRegistration
active: ServiceWorker {scriptURL: 'http://127.0.0.1:5500/sw.js',
state: 'activated', onstatechange: null, onerror: null}
backgroundFetch: BackgroundFetchManager {}
cookies: CookieStoreManager {}
installing: null
navigationPreload: NavigationPreloadManager {}
onupdatefound: null
paymentManager: PaymentManager {instruments: PaymentInstruments,
userHint: ''}
periodicSync: PeriodicSyncManager {}
pushManager: PushManager {}
scope: "http://127.0.0.1:5500/"
sync: SyncManager {}
updateViaCache: "imports"
waiting: null
[[Prototype]]: ServiceWorkerRegistration
Also the I register the service worker in a file name app.js like this:
if('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw.js')
.then((reg) => console.log('Service Worker registered.', reg))
.catch((err) => console.log('Service Worker not registered.', err));
}