I inherited an Angular app using a service worker.
Sometimes when I refresh the page for a small second I see a Chrome error page:

And just after the real page is displayed.
When I check in the network tab I have those:

So the first page load is failed for a network issue then the exact same page is provided by the service worker just after.
I was able to reproduce it on a local server so I doubt it's a real network error (and every other files can be loaded without any issue).
In the service worker logs I got:
Console: {"lineNumber":0,"message":"The FetchEvent for "https://..." resulted in a network error response: the promise was rejected.","message_level":2,"sourceIdentifier":1,"sourceURL":""}
Console: {"lineNumber":0,"message":"Uncaught (in promise) UnknownError: Unexpected internal error.","message_level":3,"sourceIdentifier":1,"sourceURL":"https://.../ngsw-worker.js"}
In Angular our config seems quite straightforward, the import in the root module :
ServiceWorkerModule.register('./ngsw-worker.js', {
enabled: true,
}),
For my tests "true" is hardcoded but it's in the config file. In some environment it's disabled then we don't have this issue anymore...
The ngsw-config:
{
"index": "/index.html",
"assetGroups": [
{
"name": "app",
"installMode": "prefetch",
"resources": {
"files": [
"/favicon.ico",
"/manifest.json",
"/index.html",
"/*.css",
"/*.js"
]
}
}
]
}
@angular/core: ~13.2.3 @angular/service-worker: ^13.2.3
Any help/hint is welcome!
Update
I removed index.html from my ngsw-config.json file to prevent it to be cache by the service worker :
"index": "", "assetGroups": [ { "name": "app", "installMode": "prefetch", "resources": { "files": [ "/favicon.ico", "/manifest.json", "/.css", "/.js" ] } }]
It's indeed not cache anymore but it still intercepted by the service worker and it's still in error sometimes:
If I check the service worker's option "bypass for network" in Chrome developer tool I don't get this error anymore.
