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