From fe635b193bf888d9528a102e2ddb70542c07399c Mon Sep 17 00:00:00 2001 From: Daniel LaCosse <3759828+daniellacosse@users.noreply.github.com> Date: Thu, 17 Oct 2024 10:01:41 -0400 Subject: [PATCH 1/2] docs(mobileproxy): explain how to use a proxy in an iOS WKWebView --- x/mobileproxy/README.md | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/x/mobileproxy/README.md b/x/mobileproxy/README.md index 0456f5b9..d6231e99 100644 --- a/x/mobileproxy/README.md +++ b/x/mobileproxy/README.md @@ -555,7 +555,28 @@ We are working on instructions on how use the local proxy in a Webview. On Android, you will likely have to implement [WebViewClient.shouldInterceptRequest](https://developer.android.com/reference/android/webkit/WebViewClient#shouldInterceptRequest(android.webkit.WebView,%20android.webkit.WebResourceRequest)) to fulfill requests using an HTTP client that uses the local proxy. -On iOS, we are still looking for ideas. There's [WKWebViewConfiguration.setURLSchemeHandler](https://developer.apple.com/documentation/webkit/wkwebviewconfiguration/2875766-seturlschemehandler), but the documentation says it can't be used to intercept HTTPS. If you know how to use a proxy with the WKWebView, please let us know! +As of iOS 17, you can add a proxy configuration to a `WKWebView` via its `WKWebsiteDataStore` property. + +```swift +let configuration = WKWebViewConfiguration() + +let endpoint = NWEndpoint.hostPort( + host: NWEndpoint.Host(proxyHost), + port: NWEndpoint.Port(proxyPort)! +) +let proxyConfig = ProxyConfiguration.init(httpCONNECTProxy: endpoint) + +let websiteDataStore = WKWebsiteDataStore.default() +websiteDataStore.proxyConfigurations = [proxyConfig] + +// Other webview configuration options... see https://developer.apple.com/documentation/webkit/wkwebviewconfiguration + +let webview = WKWebView( + configuration: configuration, +) + +// use this webview as you would normally! +``` ## Clean up From 49f8546bdf81ae118fde7532458f9e6ead1bfe61 Mon Sep 17 00:00:00 2001 From: Daniel LaCosse <3759828+daniellacosse@users.noreply.github.com> Date: Thu, 17 Oct 2024 12:12:31 -0400 Subject: [PATCH 2/2] Update x/mobileproxy/README.md Co-authored-by: Vinicius Fortuna --- x/mobileproxy/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/mobileproxy/README.md b/x/mobileproxy/README.md index d6231e99..a45f0214 100644 --- a/x/mobileproxy/README.md +++ b/x/mobileproxy/README.md @@ -555,7 +555,7 @@ We are working on instructions on how use the local proxy in a Webview. On Android, you will likely have to implement [WebViewClient.shouldInterceptRequest](https://developer.android.com/reference/android/webkit/WebViewClient#shouldInterceptRequest(android.webkit.WebView,%20android.webkit.WebResourceRequest)) to fulfill requests using an HTTP client that uses the local proxy. -As of iOS 17, you can add a proxy configuration to a `WKWebView` via its `WKWebsiteDataStore` property. +As of iOS 17, you can add a proxy configuration to a `WKWebView` via its [`WKWebsiteDataStore` property](https://developer.apple.com/documentation/webkit/wkwebviewconfiguration). ```swift let configuration = WKWebViewConfiguration()