0

I'm trying to completely disable all handling of cookies in a WKWebView.

There's a straightforward way to disable cookies for the initial request to load a page (see Disabling cookies in WKWebView):

let url = URL(string: "http://example.org")!
var urlRequest = URLRequest(url: url)
urlRequest.httpShouldHandleCookies = false
webView.load(urlRequest)

But any subsequent requests performed by the web view (e.g. when the user clicks on a link to navigate to another page) do include cookies. Inspecting the HTTP traffic generated by the web view shows that the Cookie header is being set on those requests, which is the behaviour I'd like to disable.

Clearing the contents of WKWebsiteDataStore or the WKHTTPCookieStore has no effect either as these transient cookies do not appear in the store when using a nonPersistent store.

Is there any mechanism for stopping cookies to be included for all requests in the WKWebView on iOS?

Arnold
  • 2,390
  • 1
  • 26
  • 45
  • `httpShouldHandleCookies` doesn't disable cookies, it simply overrides default handling of the cookies for that particular request. I don't know if there's a direct way to actually _disable_ cookies - I haven't heard. One workaround would be via `WKHTTPCookieStore`, where you can register `WKHTTPCookieStoreObserver` and delete cookie as soon as you were notified that it was added... – timbre timbre Oct 10 '22 at 23:04
  • Unfortunately it does not seem this is supported for WKWebView, see also https://developer.apple.com/forums/thread/16847. – Christos Koninis Oct 11 '22 at 06:58

0 Answers0