ServiceWorker Support in iOS WKWebView

  1. Is ServiceWorker supported on WKWebView? As per Mozilla Developer Network(MDN Web) docs[1] its not supported, but our research shows that ServiceWorker becomes available for a domain in WKWebView 1) if the domain is allowlisted in app-bound domains[2] or 2) if app is registered as default browser(this can not be considered for our app as its not a browser).

  2. How to enable ServiceWorker on WKWebView? Is adding domain as app-bound domain the right/only way to enable ServiceWorker on WKWebView? We didn't find any official documentation about this.

  3. Can WebView get ServiceWorker support by default without enabling app bound domains since that is not an option for our app? Our app needs to support more than 10 domains. Powerful APIs such as JavaScript injection, cookie manipulation, event handlers are by default available to all domains/WebView instances even if App doesn't enable app-bound domains. Is it possible to do same for ServiceWorker?

  4. If ServiceWorker can not be supported by default then can Apple provide a feature by which ServiceWorker will be enabled in App for all the domains?

  5. Apple enforces maximum of 10 app-bound domains. Is it possible to remove this limit and provide a way to dynamically add to this list at the time of a request?

[1] https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker#browser_compatibility

[2] https://webkit.org/blog/10882/app-bound-domains/

Answered by Engineer in 823600022

There's no supported way for you to explicitly support service workers in iOS WKWebView with the APIs currently available. If you'd like us to consider adding the necessary functionality, please file an enhancement request using Feedback Assistant. Once you file the request, please post the FB number here. If you're not familiar with how to file enhancement requests, take a look at Bug Reporting: How and Why?

There's no supported way for you to explicitly support service workers in iOS WKWebView with the APIs currently available. If you'd like us to consider adding the necessary functionality, please file an enhancement request using Feedback Assistant. Once you file the request, please post the FB number here. If you're not familiar with how to file enhancement requests, take a look at Bug Reporting: How and Why?

Thank you for your response.

Based on your response, I understand that even though ServiceWorker can be enabled with app-bound domains (max for 10 domains), its not recommended. Please correct me if I am wrong.

I will file enhancement request on adding ServiceWorker support in iOS WKWebVIew.

Another way to enable ServiceWorker is by making app a default browser, but that is not an option for our app. https://developer.apple.com/documentation/xcode/preparing-your-app-to-be-the-default-browser#Use-default-browser-capabilities

Is it possible for me to upvote this feedback? Our web application utilizes service workers to deal with transient offline data collection, but some of our clients are accessing our webapp via iOS apps (such as ClassLink) that maintain the user's authentication for launching them into other web-based applications. So the lack of ServiceWorker support in iOS webview presents a problem for reliable data collection.

ServiceWorker Support in iOS WKWebView
 
 
Q