swift – WKWebView Proxy Configuration Not Working on iOS 17


I’m working on an iOS application that uses WKWebView to load web content, and I need to configure the web view to use a proxy server with authentication. I’m targeting iOS 17 and using the latest APIs available for setting up a proxy within WKWebView. Here’s the relevant part of my code:

let webConfiguration = WKWebViewConfiguration()

let endpoint = NWEndpoint.hostPort(host: proxyHost, port: proxyPort)
let proxyConfig = ProxyConfiguration.init(httpCONNECTProxy: endpoint)
proxyConfig.applyCredential(username: proxyUsername, password: proxyPassword)
let websiteDataStore = WKWebsiteDataStore.default()
websiteDataStore.proxyConfigurations = [proxyConfig]
webConfiguration.websiteDataStore = websiteDataStore

webView = WKWebView(frame: .zero, configuration: webConfiguration)
webView.navigationDelegate = self
view.addSubview(webView)

let request = URLRequest(url: URL(string: "https://whatismyipaddress.com/")!)
webView.load(request)

Despite setting the proxy configuration and applying credentials as shown, the WKWebView fails to load the requested URL through the proxy. When I attempt to load a page, I encounter a native popup saying “Proxy Authentication Required” asking for the proxy password, even though it’s already provided in the code.

I’ve also implemented the webView(_:didFailProvisionalNavigation:withError:) delegate method, and it’s giving me an “Authentication error” with NSPOSIXErrorDomain Code=80.

I’m not sure why this is happening since I believe I’ve followed the correct steps to configure the proxy with authentication for WKWebView. Here are my questions:

  1. Is there a known issue with proxy configuration for WKWebView in iOS 17?
  2. Are there additional steps or configurations required to successfully authenticate and use a proxy with WKWebView?
  3. Why might the webView(_:didFailProvisionalNavigation:withError:) method report an authentication error despite providing credentials?

Any advice or insight into what might be causing this issue and how to resolve it would be greatly appreciated. Thank you in advance!

I attempted to programmatically configure a proxy with authentication for a WKWebView by using the new ProxyConfiguration API available in iOS. I expected the WKWebView to navigate through the proxy using the provided credentials without prompting for authentication. Instead, upon loading a URL, I was faced with a native iOS popup asking for proxy authentication credentials, and the WKWebView failed to load the page, reporting an “Authentication error” via the webView(_:didFailProvisionalNavigation:withError:) delegate method. This was unexpected, as my code supplies the proxy credentials directly.

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img