Reputation: 10283
Service Workers were available in WKWebView
in iOS 11.3 betas, but do not appear to be available in the final GM version of iOS 11.3.
Does anyone know how to re-enable Service Workers in WKWebView
on iOS?
Upvotes: 23
Views: 12650
Reputation: 10283
Service Workers in WKWebView
now require an entitlement:
com.apple.developer.WebKit.ServiceWorkers
, which should be added to the .entitlements
plist as a Boolean
with a value of YES
.
Currently this will only work in the iOS Simulator, until such time as Apple update the Apple Developer Portal to make it possible to create App IDs and Provisioning Profiles containing this entitlement.
For more information see this bug: https://bugs.webkit.org/show_bug.cgi?id=182865 and associated change set: https://trac.webkit.org/changeset/228933/webkit
EDIT: Unfortunately still seems to be the case in iOS 16.
Upvotes: 25
Reputation: 467
This entitlement is now available with iOS 14 (com.apple.developer.web-browser). Due to the fact that Apple now allows other browsers being the default option there is a new entitlement available which also includes service workers!!!
The updated documentation can be found here: Apple Docs
The following is the interesting part:
Using Default Browser Capabilities
- Apps that use the com.apple.developer.web-browser managed entitlement can:
- Be an option for the user to choose as their default browser.
- Load pages from all domains with full script access.
- Use Service Workers in WKWebView instances.
But this comes with big drawbacks. Universal links won't work anymore and there is a list of not allowed key for the info.plist (see link).
Can anyone already confirm having a WKWebview using this entitlement in the app store?
UPDATE:
A better solution might be using App Bound Domains.
This works for up to 10 domains and you restricts your WKWebview to these domains! It won't work for other websites. You do not have to own the domain.
Add the following to you WKWebviewConfiguration:
let configuration = WKWebViewConfiguration()
configuration.limitsNavigationsToAppBoundDomains = true
In your info plist add key with WKAppBoundDomains:
<key>WKAppBoundDomains</key>
<array>
<string>example.com</string>
<string>example2.com</string>
</array>
After a quick test this returned 'serviceWorker' in navigator === true
.
If this goes through the review process this might be a breakthrough for PWAs!!!!
Upvotes: 16