Post

Replies

Boosts

Views

Activity

WKWebView sometimes lose cookies after the app returns from suspension
I embedded a WKWebView in my SwiftUI app, and loaded a list of HTTPCookie into a WKWebViewConfiguration object: var wkWebViewConfiguration = WKWebViewConfiguration() let cookies: [HTTPCookie] = ... // logic that creates a list of HTTPCookie for cookie in cookies { wkWebViewConfiguration.websiteDataStore.httpCookieStore.setCookie(cookie) } This logic works but when the app returns to the foreground from a long suspension (more than an hour), sometimes the web view reloads the URL but the cookies are gone. I suspect the web content process is terminated and add a logic to reload the URL and the cookies on process termination: // WKNavigationDelegate method func webViewWebContentProcessDidTerminate(_ webView: WKWebView) { // reload the URL and cookies here } but the issue still persist, could there be any other reasons that the cookies are lost or is my above solution not sufficient to handle web content process termination? This issue is quite random to me and there is no deterministic way to reproduce it.
5
1
2.8k
Feb ’24