Connection refused when call ngsw-worker.js file and Service worker is not registering
See original GitHub issueI can’t register service worker in capacitor webview I used angular and capacitor 1.0.0-beta.24
I think that URL schema need to be https which service worker required, How to make this https ? or what is the suitable solution to register SW My package.json is :
and the problem is : (This is from Android Emulator)
Failed to load resource: net::ERR_CONNECTION_REFUSED
Uncaught Error: Uncaught (in promise): TypeError: Failed to register a ServiceWorker: An unknown error occurred when fetching the script.
TypeError: Failed to register a ServiceWorker: An unknown error occurred when fetching the script.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:13 (5 by maintainers)
Top Results From Across the Web
Service Worker Registration Failed - Stack Overflow
Solved: First thing is service worker only works in secure mode either in https or localhost. It doesnot work in local resources like ......
Read more >Angular service worker introduction
For service workers to be registered, the application must be accessed over HTTPS, not HTTP. Browsers ignore service workers on pages that are...
Read more >Angular 5 Service Worker - Medium
Important to note is that fact that the service worker registration is only done by calling ServiceWorkerModule.register('/ngsw-worker.js') only if we're in ...
Read more >Capacitor: Service Worker - Ionic Forum
Connection refused when call ngsw -worker. js file and Service worker is not registering. The issue is not with SW registration that is...
Read more >CSP: worker-src - HTTP - MDN Web Docs
The HTTP Content-Security-Policy (CSP) worker-src directive specifies ... serviceWorker.register("https://not-example.com/sw.js"); </script>
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
So, the problem is the web worker requests don’t go through the regular shouldInterceptRequest.
You can use this workaround https://stackoverflow.com/questions/55894716/how-to-package-a-hosted-web-app-with-ionic-capacitor
You don’t need a plugin, you can use a similar code in the
MainActivity.java
like this:But notice that it requires SDK 24 and Capacitor supports SDK 21, so it won’t work on 21-23
Is there any news about the matter? I am having the same issue