HTTP proxy support using WKWebView

Is there a way to configure WKWebView to pass through an HTTP proxy? I know that this is possible with NSURLSession directly, but I want to configure it so that all requests through the WKWebView browser go through the proxy.

+6
source share
1 answer

NSURLSessionConfiguration has a direct interface (connectionProxyDictionary) for this, so it can be easily executed

But WkWebView does not have such a direct interface as it does, it requests, displays content outside the process and therefore you can imagine how the WkWebview instance is isolated from the rest of your application.

WkWeView even ignores cookies (NSHTTPCookieStorage), caches (NSURLCache) and credentials (NSCredentialStorage) NSURLSession and NSURLConnection, and these network classes cannot access cookies, caches, and credentials of a WkWebView instance.

UIWebView does not do this outside the process, so you can use NSURLProtocol, as shown in the CustomHTTPProtocol sample for the proxy server.

As with iOS 10, WkWebView does not support NSURLProtocol, so you cannot proxy using WkWebView.

If your proxy server supports tunneling (VPN), you can use NetworkExtension.framework and its classes (NEVPNManager, NEVPNProtocol, NEVPNConnection, etc.) to direct all the network traffic of your application through your proxy server.

Here is a tutorial on how to do this

+3
source

Source: https://habr.com/ru/post/1013046/


All Articles