I was able to confirm that on iOS 17, using proxyConfiguration with WkWebView does work. Here's a snippet from my working code,
import WebKit
class WebKitViewModel: ObservableObject {
let webView: WKWebView
@Published var urlString: String = "https://example.com"
init() {
webView = WKWebView(frame: .zero)
}
func loadUrl() {
guard let url = URL(string: urlString) else {
return
}
var request = URLRequest(url: url)
let endpoint = NWEndpoint.hostPort(host: "127.0.0.1", port: 9077)
let proxyConfig = ProxyConfiguration.init(httpCONNECTProxy: endpoint)
let websiteDataStore = WKWebsiteDataStore.default()
websiteDataStore.proxyConfigurations = [proxyConfig]
webView.configuration.websiteDataStore = websiteDataStore
webView.load(request)
}
}
It will even work with HTTPS requests, assuming you have a CA certificate for your proxy installed as a trusted root cert on your device and that the proxy's certs (dummy certs if doing MiTM) and the CA cert satisfy Apple's requirements for trusted certs on iOS 13+ (https://support.apple.com/en-us/HT210176).
One issue that I am still having is that I cannot add a header to every HTTP request coming from the WkWebView, which is crucial to my proxy's functionality. I am able to add a header to the initial URL request, but if that URL request results in additional requests (which is how every website works), the header is not added to the subsequent requests. But I guess this is a separate, known issue maybe, closely related to this thread, https://developer.apple.com/forums/thread/14462?
Hope this helps out other people who are interested in using a proxy with WebKit.