Closed lukas-zech-software closed 6 years ago
We don’t yet support service worker polyfilling when running natively. Not sure we want to, open to any thoughts or comments
How else am I going to implement stuff like background sync and push notifications in my PWA and deploy that to the app stores wrapped via capacitor?
Should stuff like that be wrapped in a Plugin, which uses service workers if the target is web and native APIs else?
I was under the impression, that we could use service workers everywhere
@lukas-zech-software Just wanted to jump in here to clear things up. Because of security, service workers can only be used on an https
connection. Capacitor, Cordova and any other native interop layer do not operate over https connections, therefore service workers will not work. I am also not completely sure that the chrome webview on Android even implements service workers (not sure on iOS either).
ok, so the stuff I wanted to implement with service workers should rather use plugins to use the native implementation for each platform.
so im eager to see push notifications implemented: https://github.com/ionic-team/capacitor/issues/380
@jgw96 I guess you could still polyfill service workers on http still, a pwa without service-workers wouldn't really be a pwa as the progressive wouldn't exist without huge changes to the original code.
I'm a bit stumped here - I was planning on using service workers to intercept HTTP requests and manually manage the cache. While navigator.serviceWorker
exists on Android, I get these errors when calling navigator.serviceWorker.register('sw.js')
:
An unknown error occurred when fetching the script.
Failed to load resource: net::ERR_CONNECTION_REFUSED
(index):1 Uncaught (in promise) TypeError: Failed to register a ServiceWorker: An unknown error occurred when fetching the script.
I know sw.js
is accessible because fetch('sw.js')
resolves, so it looks like the Android Chrome WebView is denying service workers. However, according to this WebViews do support service workers.
@diachedelic If I'm not mistaken - Capacitor launches its own web server which may or may not have an SSL cert. If it does use SSL it may be an issue with it being self-signed.
Its been a few months since I've used Capacitor, so if there is an option to load your PWA via URL instead I would give that a shot.
I was able to run our PWA+SW using this repo https://github.com/xtools-at/Android-PWA-Wrapper just to verify that it wasn't an issue with webview.
@adamlacombe by "load your PWA via URL" do you mean a remote URL rather than local?
And yes, it is running on HTTPS but i suppose it will be self-signed
Looks like there's an unanswered stackoverflow question Service worker with self signed certificate on Android WebView
Please, stop commenting on a closed issue that is not even related to what you are commenting about as the original issues is about iOS
I'm trying to bundle a PWA in an iOS app. The PWA should use a ServiceWorker.
I used the starter app provided by
npx @capacitor/cli create
and tried to enable the ServiceWorker there. My www/index.html now looks like thisAs mentioned in the snippet
'serviceWorker' in navigator
returns false, therefore the service worker cannot be installed.Am I missing something?
I am building an emulating the App on XCode (Version 9.4 (9F1027a)) with iOS 11.4 as deployment target.
The same code seems to work on Android 8.1 emulated with Android Studio 3.1.3