I'm trying to set a WKWebView process pool's per-domain cookie value explicitly / programatically. I want to emulate exactly what happens when a server sends back a Set-Cookie header. The research I've done here and elsewhere says to inject that as JavaScript. I don't like that on principle -- it feels wrong. I want to talk to the "guy in charge" (WebKit internal cookie data structure) not inject a hack at the last second through a second language (JavaScript).
I'm also getting a maddening 1% failure rate of this method, likely due to 1) The highly asynchronous nature of WKWebView interaction, since all the networking and JavaScript computation happens in a separate process and 2) The fact that I'm reusing the same WKWebView multiple times when a login session expires, and resetting the document.cookie script just before forcing the page to reload.
I'm surprised there's nothing like WKWebSiteDataStore.addCookie(value: String, inDomain: NSURL); the fact that it has removeDataOfTypes(...) without add or inject screams "gaping design hole" to me.
References:
ios9 - Multiple WkWebView sharing cookie WKProcessPool() doesn't work?