5

I used the Angular 6 CLI to generate and register the service-worker in the application, when I manually enable offline mode, the service-worker job is correct, but as soon as I try to audit using the lighthouse, it tells me that the service worker is not registered.

enter image description here

JonnyBGod
  • 35
  • 2
  • 6
  • Can you see your worker in Chrome Devtools/Application->Service workers tab without a Lighthouse? – mutantkeyboard May 28 '18 at 11:23
  • Yeah, it's rigistered – Konstantin Kudelko May 29 '18 at 08:43
  • Have you tried following [this](https://codelabs.developers.google.com/codelabs/offline/#0) guide? It explains how to tune your service worker to return 200 when offline. Also [docs](https://developers.google.com/web/tools/lighthouse/audits/registered-service-worker) should give you a pretty decent start. If it doesn't work, could you share your service worker code. It might give some more insight on what's going on. – mutantkeyboard May 29 '18 at 09:15
  • I just use Angular 6 CLI for generate service-worker, like I see he is registered, but any way plugin say to me like it's not working – Konstantin Kudelko May 30 '18 at 16:19
  • Did you ever find a solution? – David Dal Busco Aug 19 '18 at 19:06
  • I had the same issue. It initially worked but once I added a lazy load child module, the test failed and complained service worker not registered. But the website still loads even if I turned off the server. – Xin Zhang Nov 27 '18 at 23:53

1 Answers1

0

It's mostly because you might be using angularfire2.

This can be solved by adding the below in main.ts file

  platformBrowserDynamic().bootstrapModule(AppModule).then(() => {
    if ('serviceWorker' in navigator && environment.production) {
    navigator.serviceWorker.register('ngsw-worker.js');
    }
    }).catch(err => console.log(err));

Hope it helps.

Anil Kumar Reddy A
  • 665
  • 11
  • 29