Reputation: 472
I have a hosted web application built with Create React App that utilizes a service worker to allow the application to be opened and viewed when offline.
I am using Cordova as a hybrid app wrapper which uses cordova-plugin-inappbrowser to load the external web content and display it to the user on a native ios or android device.
I would like the application to be able to be opened when the network is down (assuming the user has already opened it once and the content has been cached). From what I can tell, it appears that the service worker is correctly running and caching the content when it is loaded in the inappbrowser and the internet is working. It console log output indicates that this is occurring.
If the application is close and re-opened with the network disabled, the application reports a network error and will not load. Here is the line of code producing the error:
inAppBrowserRef = cordova.InAppBrowser.open(url, '_blank', 'location=no,zoom=no,toolbar=no,hidenavigationbuttons=yes'); //open the in app browser with no location bar
The code appears to try and validate that the url exists before proceeding to execute any service worker code. Is there a way to tell the InAppBrowser to load from the cached content first instead of the network Url?
Upvotes: 1
Views: 932
Reputation: 11
Service workers are available in iOS 14 for WKwebview and there is a version of the IAB which uses it. com.apple.developer.WebKit.ServiceWorkers should be added to the .entitlements plist as a Boolean with a value of YES. The website that you are loading in the IAB should be https or localhost.
Upvotes: 1