Intermittently Service worker is not working for webkit (WKWebview) in IOS 15

We have created a sample HTML page with service worker to enable offline load for iOS 15, And we are loading the sample HTML page in IOS Sample App .

Sample app contains the WKWebview(which is webkit framework) which loads the sample HTML. we have added the app bound domain in the Info.plist to support the Service Worker.

AppBoundDomains in Info.plist is

<key>WKAppBoundDomains</key>
	<array>
		<string>https://ottapp-appgw-client.dev.mr.tv3cloud.com</string>
	</array>

And configured the WKWebViewConfiguration for WKWebView through code:

if (@available(iOS 14.0, *)) {
            configuration.limitsNavigationsToAppBoundDomains = YES;
 } 

Working Scenario is :

When we launch the application in online mode for the first time, it is successfully registering the ServiceWorker. On launching the application in offline mode, it successfully loads the offline page in iOS 15.

Issue is :

After repeatedly killing and relaunching the application many time (say 5-6 times), we are seeing the blank screen instead of loading the offline page (which is Service Worker Enabled)

we are receiving the below error when service worker is not working:

[Process] 0x10581f018 - [pageProxyID=5, webPageID=6, PID=8803] WebPageProxy::didFailProvisionalLoadForFrame: frameID=3, domain=NSURLErrorDomain, code=-1009
2022-03-21 19:32:40.651305+0530 WKWebViewSample[8800:1490156] didFailProvisionalNavigation

Issue Repro rate 5 Out of 10

Added the logs for the same

  • Having the same problem here. Including that if you close the app, go to off-line (airplane) mode, and the re-open, it does not load.

  • I've ended up using this workaround successfully, basically you load a local page that redirects to your actual page. For some reason this makes the service worker always work and the page load off-line from the start.

    let html = """<html><head><meta http-equiv="Refresh" content="0; url='\(YOUR_URL_HERE)'" /></head><body></body></html>""" webView.loadHTMLString(html, baseURL: nil)

  • Thank you for posting this work-around. I tried it in my app to support opening while offline, but I still get the WebPageProxy::didFailProvisionalLoadForFrame error. I wonder if there is something else that must be configured in order for it to work fully offline.

Add a Comment

Replies

deleted

Is there any resolution available for this issue. I am facing this issue with AppBoundDomains and Service worker. The page doesn't load unless the application is deleted and resinstalled.