9

From my understanding and trying out some code, we can only monitor page navigation requests using

func webView(_ webView: WKWebView, decidePolicyFor navigationResponse: WKNavigationResponse, decisionHandler: @escaping (WKNavigationResponsePolicy) -> Void)
{
    if // some condition
    {
        decisionHandler(.allow) // to allow the page navigation.
    }
    else
    {
        decisionHandler(.cancel) // to cancel the page navigation.
    }
}

But is there any way to monitor and block some ajax requests in WKWebView?

And also to capture the ajax response.

unknownymouse
  • 399
  • 1
  • 5
  • 21
  • Facing kind of the same problem have you resolved this issue? – jailani Feb 06 '18 at 06:48
  • @jailani Nope.. – unknownymouse Jul 08 '18 at 20:07
  • Did you consider injecting a user script which overwrites the `XMLHttpRequest` object with a custom proxy object? It should work similar to [bridging web notifications to a native app](https://stackoverflow.com/a/58615934/769502). – p13n Nov 29 '19 at 10:36

0 Answers0