Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection refused when call ngsw-worker.js file and Service worker is not registering #1655

Closed
minajacob opened this issue Jun 12, 2019 · 13 comments

Comments

@minajacob
Copy link

I 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 :

image

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.

image

@minajacob minajacob changed the title Connection refused when call ngsw-worker.js file and Service Worker Service worker is not registering Connection refused when call ngsw-worker.js file and Service worker is not registering Jun 12, 2019
@jcesarmobile
Copy link
Member

What are you doing with the service workers?
Can you provide a sample app?

@minajacob
Copy link
Author

Thanks @jcesarmobile for your reply
I created a PWA app that uses service worker for caching some requests and offline support. This work nice in web but not sure how this PWA app should work well inside the capacitor due to this issue.

@jcesarmobile
Copy link
Member

So, can you provide a sample app?

@jcesarmobile jcesarmobile added the needs reply needs reply from the user label Jul 24, 2019
@minajacob
Copy link
Author

I create a sample app in this repository
https://github.com/minajacob/capacitor-sw

@dimitrios1988
Copy link

Is there any news about the matter? I am having the same issue

@jcesarmobile
Copy link
Member

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:

if(Build.VERSION.SDK_INT >= 24 ){
      ServiceWorkerController swController = ServiceWorkerController.getInstance();

      swController.setServiceWorkerClient(new ServiceWorkerClient() {
        @Override
        public WebResourceResponse shouldInterceptRequest(WebResourceRequest request) {
          return bridge.getLocalServer().shouldInterceptRequest(request);
        }
      });
    }

But notice that it requires SDK 24 and Capacitor supports SDK 21, so it won't work on 21-23

@kenezetele
Copy link

This workaround doesnt work anymore with the latest webview update (v90). If the app had a worker registered, doesnt load at all, and if not, cant register the worker. For me it seems like ServiceWorkerClient gets overridden even if I am overriding it. Do you have any other workaround suggestions?

@jcesarmobile
Copy link
Member

If google broke something you’ll have to report it to google, they probably didn’t do it on purpose

https://bugs.chromium.org/p/chromium/issues/list?q=component:Mobile%3EWebView

@kenezetele
Copy link

I am making a report. Do you think is it possible to make a workaround until they fix it? The app is broken in production. Reinstalling it removes the service worker but then the modules are loaded slower from the app than from the cache.

@laurentgoudet
Copy link
Contributor

I am making a report. Do you think is it possible to make a workaround until they fix it? The app is broken in production. Reinstalling it removes the service worker but then the modules are loaded slower from the app than from the cache.

Did you end up making a report @kenezetele? The v91 WebView update seems to have fixed the issue

@kenezetele
Copy link

kenezetele commented May 27, 2021

Did you end up making a report @kenezetele? The v91 WebView update seems to have fixed the issue

Yes, I have made a report with a sample app to reproduce the issue. They have fixed it from there.
https://bugs.chromium.org/p/chromium/issues/detail?id=1204098#c1

@dylanvdmerwe
Copy link

dylanvdmerwe commented Nov 26, 2021

Note that this does not work:
image

When the site is served from the service worker capacitor is not injected:
image
image

Issue raised here.

@ionitron-bot
Copy link

ionitron-bot bot commented Nov 10, 2022

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Nov 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants