Request for Native AJAX API Request Interception Support in WKWebView

Hello WebKit Team,

I’m writing to ask if iOS provides a native way to intercept AJAX (XMLHttpRequest or fetch) calls inside WKWebView.

On Android, this is handled via: shouldInterceptRequest(WebView view, WebResourceRequest request)

but iOS currently seems to have no equivalent.

We’ve tried:

WKURLSchemeHandler → works only for custom schemes

URLProtocol with WKProcessPool → unreliable for AJAX in WebView

JavaScript injection → partial and unofficial

Could you please clarify:

Is there a recommended native approach to intercept AJAX requests?

If not supported, is it planned for future releases?

Any official workaround or guidance?

This is critical for debugging, analytics, and compliance in hybrid apps.

Answered by DTS Engineer in 867204022

Usually this sort of thing is done using the webView(_:decidePolicyFor:preferences:decisionHandler:) method on the WKWebView's WKNavigationDelegate.. This is a method you normally use to monitor and control the URLs your WKWebView is loading and provides your app with an opportunity to intercept URLs before they are loaded. You can also use it as a mechanism for simply monitoring the urls that are being loaded into a WKWebView.

Usually this sort of thing is done using the webView(_:decidePolicyFor:preferences:decisionHandler:) method on the WKWebView's WKNavigationDelegate.. This is a method you normally use to monitor and control the URLs your WKWebView is loading and provides your app with an opportunity to intercept URLs before they are loaded. You can also use it as a mechanism for simply monitoring the urls that are being loaded into a WKWebView.

Thanks for the suggestion.

However, my question was specifically about intercepting AJAX API calls, not regular page navigations. The webView(_:decidePolicyFor:preferences:decisionHandler:) method only helps intercept navigation-level URL loads, whereas AJAX/XHR requests happen internally via JavaScript and don’t trigger navigation actions.

So, I'm looking for a way to inspect or intercept XHR / fetch API calls initiated inside the WebView, which unfortunately cannot be handled using WKNavigationDelegate.

Request for Native AJAX API Request Interception Support in WKWebView
 
 
Q