2

I am attempting to setup PWA on my ionic 4 application however i get an error like this below when auditing with lighthouse in chrome.

enter image description here

I followed the tutorial on this link create-an-ionic-4-pwa-with-capacitor

I cloned their project and it seems to be working on my local but i can't seem to figure out the difference with my app.

I would like to see the add to home screen panel at the bottom but it seems it will not show if i don't fix this error.

What i already tried:

  • Deploying on https server
  • forcing service worker enabled to true in app.module ServiceWorkerModule.register('ngsw-worker.js', { enabled: true })

However it did not fix it. Last thing i can do is downgrading to angular 7.2 if i cannot really find a way.

my version of angular and ionic are the latest which is listed below:

  • "@angular/pwa": "^0.801.1",
  • "@angular/core": "~8.1.1",
  • "@ionic/angular": "^4.6.2",
  • "@angular/cli": "~8.1.1",

manifest.webmanifest content:

"display": "standalone",
"scope": "/",
"start_url": "/",

[UPDATE]

i tried downgrading to angular 7.2 and it seems working now. However if someone can answer if how to make it work in angular 8 that will be great

1 Answer 1

3

It seems the issue was not with angular 8 as i have tried creating a new app from scratch and it worked. However i have found a solution in my case.

there is a property called registrationStrategy when registering a serviceworker in app.module.ts. By default it has a value of registerWhenStable. The fix was changing this to registerImmediately

ServiceWorkerModule.register('ngsw-worker.js', { enabled: environment.production, registrationStrategy: 'registerImmediately' })

Here are the possible values for that based on its source code

enter image description here

So my app is somehow not stable enough on first load reason why the service worker did not run properly which i need to investigate. Posting it here hopefully it will help somebody.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.