Is there a way to configure WKWebView to go through a HTTP Proxy server? I know this is possible with NSURLSession directly, but I want to configure it so that all requests through the WKWebView browser go through a proxy.
Since then, we've recommended that you adopt WKWebView instead of UIWebView and WebView — both of which were formally deprecated. New apps containing these frameworks are no longer accepted by the App Store.
A WKWebView object is a platform-native view that you use to incorporate web content seamlessly into your app's UI. A web view supports a full web-browsing experience, and presents HTML, CSS, and JavaScript content alongside your app's native views.
The WKWebView is a modern API applying all the modern web security mechanisms, it's still maintained by Apple and gets updates. The good thing about WKWebView is that it does out-of-process rendering, so if the attackers find a memory corruption vulnerability in it, your application's process is still isolated.
NSURLSessionConfiguration has a direct interface(connectionProxyDictionary) to do that , so it can be done easily
But, WkWebView does not have any direct interface like that,it requests ,renders the content out-of-process and so you can imagine like WkWebview instance is sandboxed from the rest of your app
WkWeView even ignores the cookies(NSHTTPCookieStorage), caches(NSURLCache) and Credentials(NSCredentialStorage) of NSURLSession & NSURLConnection likewise these network classes can't access cookies,caches and credentials of WkWebView instance.
The UIWebView does not do it out-of-process and so you can use NSURLProtocol as demonstrated in CustomHTTPProtocol sample to proxy to a server.
As of iOS 10, still there is no support for NSURLProtocol in WkWebView so you can't proxy using WkWebView.
If your proxy server supports tunnelling(VPN) then you can use NetworkExtension.framework and its classes(NEVPNManager, NEVPNProtocol, NEVPNConnection etc..) to direct all the network traffic of your app through your proxy server.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With