Posts

Post not yet marked as solved
2 Replies
2.3k Views
HiI am trying to findout a way to block the Ajax requests in webview.When any URLRequest is loaded in webview, we get delegate callbackoptional func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void)But ajax requets we don't get any callbacks. We can inject our javascript to observe request post message to app.We can post message from javascript to webkit message handler.webkit.messageHandlers.callbackHandler.postMessage(data)And in our code we can get the WKScripMessage by implemeting message handler protocolWKScriptMessageHandler protocol func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage)Note: I cannot disable the javaScript in web view. I need to block only some requests.Can anyone please suggest me, is there any way to block ajax request in native code?Thanks.
Posted
by GPB.
Last updated
.