wkwebview session persistence

I have multiple ViewControllers each with an embeded WKWebView. The application launchs an initial view controller that accesses content from the server, for which the WKWebView should store session information. When the user clicks on a tab in the TabBarController a new view controller is launched with an embedded WKWebView. This new WKWebView instance loads a new URL request for a different page within the same domain. However, it doesn't appear that the session is persisted between different instances of the WebView, because the page doesn't present correctly. I've verified that it's a WKWebView issue, by forcing a load of the same page from the original view controller and that page presents correctly. Also, I have opened the same site using the iOS Safari Browser and it presents the page correctly.

I've tried several different way's to fix this problem short of passing a single WKWebView instance around. I first tried passing a persistent WKProcessPool instance and that didn't worked. I checked the WKWebSiteDataStore object for each load request within the view controllers and it's the same object base on the memory location. I also tried passing around a persistent WKWebViewConfiguration object and that didn't work as well!

How do a persist the session storage between separate WKWebView instances??


Same problem here. Is there a solution already?

Same issue.

Love to know if there is a solution.

Use the same instance of WKProcessPool in all your WKWebViews.

Create WKWebViewConfiguration for each WKWebView you instantiate. Update processPool property to WKProcessPool instance.

Set cookies to webView.configuration.websiteDataStore.httpCookieStore. Then load your url.