Skip to content

Commit

Permalink
Merge pull request #299 from Jigsaw-Code/daniellacosse/explain_webvie…
Browse files Browse the repository at this point in the history
…w_configuration

docs(mobileproxy): explain how to use the proxy in an iOS WKWebView
  • Loading branch information
daniellacosse authored Oct 17, 2024
2 parents c7e1aea + 49f8546 commit 2cff9c6
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion x/mobileproxy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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](https://developer.apple.com/documentation/webkit/wkwebviewconfiguration).

```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

Expand Down

0 comments on commit 2cff9c6

Please sign in to comment.