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?