Bug 206741

Summary: WKWebView support for Service Workers
Product: WebKit Reporter: Krzysztof Jan Modras [:chrmod] <krzysztof.modras>
Component: WebKit2Assignee: Nobody <webkit-unassigned>
Status: NEW ---    
Severity: Normal CC: achristensen, ajuma, andreas, basix, beidson, costan, jason.jeffrey, krzysztof.modras, landsman, mjs, nathan_wild, tomac, tristan.morris, webkit-bug-importer, webkit
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: iPhone / iPad   
OS: All   

Description Krzysztof Jan Modras [:chrmod] 2020-01-24 05:27:20 PST
iOS version of Safari has some service workers capabilities. Yet WKWebView does not implement any of those. 

Is there a plan to enable service workers or a way to contribute to make it happen?
Comment 1 Radar WebKit Bug Importer 2020-02-19 01:56:45 PST
<rdar://problem/59584040>
Comment 2 Maciej Stachowiak 2020-02-19 01:59:31 PST
We're looking into ways to enable this.
Comment 3 Victor Costan 2020-04-28 11:30:01 PDT
The lack of Service Workers support in third-party browsers on iOS is hurting Chrome's AppCache removal efforts. AppCache is owned and will hopefully be removed by my team, and we would appreciate having Service Workers be available to all iOS browsers.

You can see a developer complaint at https://crbug.com/582750#c54.

My light searching turned up https://bugs.webkit.org/show_bug.cgi?id=182865, which suggests that WKWebView gates SW support on the com.apple.developer.WebKit.ServiceWorkers entitlement. I'm told that the entitlement is not available in the app console.
Comment 4 Sung Jeon 2023-03-21 21:00:08 PDT
Any updates on this issue? If the tweet by Maciej Stachowiak [1] is a valid solution, I think this issue can be closed by documenting that Service Workers would only work with App-Bound Domains.

[1]: https://twitter.com/othermaciej/status/1295434201865412608
Comment 5 tristan-morris 2023-06-26 21:32:35 PDT
Trialling this today with AppBoundDomains set, navigator.serviceWorker is exposed. But workers can only be loaded via HTTP or HTTPS protocols. 

Workers can't be loaded from a custom URL scheme (at least if set via setURLSchemeHandler - https://developer.apple.com/documentation/webkit/wkwebviewconfiguration).

Ideally it would be possible to load workers from customproto://localhost/service-worker.js for example.
Comment 6 Nathan Wild 2023-11-14 08:10:01 PST
Is there an intention in the future to make this work with custom URL schemes for loading/registering the service worker?

There's a known limitation right now with apps that are solely built on wrappers creating a WKWebView to display their content (Cordova, Capacitor etc.) that service workers aren't a possible solution for handling offline content, passing authorization headers etc. on known requests.

For example, Capacitor uses its own custom URL scheme (capacitor://) to serve content as http/https are reserved for remote content, this alone would prevent service workers from being used as they would need to be served under that protocol instead, see https://github.com/ionic-team/capacitor/issues/7069.
Comment 7 Michal 2024-03-15 08:55:01 PDT
Guys, please consider to enable this feature. Without it, the use of the web application within the web view is limited. For example, if you want to manage file uploads.