Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift 4/5 setting adding proxy to WKWebview

Tags:

I have looking for a way to set a proxy to WKWebview request with no luck.

By another hand I have been able to set proxy to http request

func createURLSessionConfiguration(_ host:String,_  port:String) -> URLSessionConfiguration {

    let config = URLSessionConfiguration.default
    config.requestCachePolicy = URLRequest.CachePolicy.reloadIgnoringLocalCacheData
    config.connectionProxyDictionary = [AnyHashable: Any]()
    config.connectionProxyDictionary?[kCFNetworkProxiesHTTPEnable as String] = 1
    config.connectionProxyDictionary?[kCFNetworkProxiesHTTPSProxy as String] = host
    config.connectionProxyDictionary?[kCFNetworkProxiesHTTPSPort as String] = port

    return config
}

But my question to you guys is how can set the proxy to the WKWebView?

I'll really appreciate your help

like image 383
user2924482 Avatar asked Apr 02 '19 19:04

user2924482


People also ask

What is the difference between UIWebView and WKWebView?

Unlike UIWebView, which does not support server authentication challenges, WKWebView does. In practical terms, this means that when using WKWebView, you can enter site credentials for password-protected websites.

What is WKWebView in Swift?

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.

How do I import WKWebView into Objective C?

You can implement WKWebView in Objective-C, here is simple example to initiate a WKWebView : WKWebViewConfiguration *theConfiguration = [[WKWebViewConfiguration alloc] init]; WKWebView *webView = [[WKWebView alloc] initWithFrame:self. view. frame configuration:theConfiguration]; webView.

What browser is WKWebView?

WKWebView. WKWebView was introduced in iOS 8 allowing app developers to implement a web browsing interface similar to that of mobile Safari. This is due, in part, to the fact that WKWebView uses the Nitro Javascript engine, the same engine used by mobile Safari.


1 Answers

HTTP proxying is not possible with WKWebView -- the NSURLProtocol registering trick doesn't work when using WKWebView (it works only with UIWebView).

A similar trick might have been possible using WKURLSchemeHandler, but it doesn't allow registering schemes that are natively handled by WKWebView, so it isn't really possible.

Source: https://forums.developer.apple.com/thread/110312#337642

like image 53
roop Avatar answered Sep 19 '22 11:09

roop