WKWebview proxying HTTP Request

Hello,
We have application which should pass traffic through https private proxy server if it needed, but I am find info that is impossible with WKWebView, only if i want send traffic we should use VPN. Is there a way to send traffic trough proxy use WKWebView.

From this link I am sure that is impossible:
https://stackoverflow.com/questions/41068675/http-proxy-support-with-wkwebview/41268348#41268348
https://stackoverflow.com/questions/55482380/swift-4-5-setting-adding-proxy-to-wkwebview?noredirect=1&lq=1
https://developer.apple.com/forums/thread/110312#337642
https://github.com/react-native-community/react-native-webview/issues/115
https://stackoverflow.com/questions/24208229/wkwebview-and-nsurlprotocol-not-working

But in this link I saw a chance create this feature:
https://stackoverflow.com/questions/40133512/intercept-request-with-wkwebview

I am try many ways, but I can't pass traffic through proxy.
Only what i can it is obtain HTML version of site through proxy.

Please help me understand all picture and dispel my doubt.

Regards, Ihor.

Answered by Systems Engineer in 633069022
There are a few long standing Enhancement Request's out there related to this topic, notably (r20545691 and r34457551). There is no API to directly intercept incoming traffic to WKWebView and send it to a proxy. There are off course Network Extension related options here, which Quinn has covered in detail on the post you mentioned. Another option might be to look into a system level PAC that can be added from the Network Configuration -> HTTP Proxy. This does not allow you to control the proxy from the WKWebView level, but does from a System Level.

Lastly, what is it that you need to do by including a proxy in your WKWebView workflow?


Matt Eaton
DTS Engineering, CoreOS
meaton3@apple.com
Accepted Answer
There are a few long standing Enhancement Request's out there related to this topic, notably (r20545691 and r34457551). There is no API to directly intercept incoming traffic to WKWebView and send it to a proxy. There are off course Network Extension related options here, which Quinn has covered in detail on the post you mentioned. Another option might be to look into a system level PAC that can be added from the Network Configuration -> HTTP Proxy. This does not allow you to control the proxy from the WKWebView level, but does from a System Level.

Lastly, what is it that you need to do by including a proxy in your WKWebView workflow?


Matt Eaton
DTS Engineering, CoreOS
meaton3@apple.com
Thank you for your answer, I am need that link of web site will be open inside WKWebView through proxy if site unavailable in my country, proxy ONLY for connection from Application.

I right you understand, I can't change proxy settings from WKWebView but i can change proxy configuration from system layer it's like a (IPhone -> Settigs -> Wi-Fi -> HttpProxy(Configure Proxy)) BUT it will be like global proxy for all connection from phone not only app. Correct me please if I am mistakes, because I am maybe not completly understand situatiation.

Regards, Ihor.

BUT it will be like global proxy for all connection from phone not only app. Correct me please if I am mistakes, because I am maybe not completly understand situatiation.

You are correct. It will apply to the whole system, not just the app. Which is the downside of this approach.


Matt Eaton
DTS Engineering, CoreOS
meaton3@apple.com
WKWebview proxying HTTP Request
 
 
Q