How can i intercept XHR calls from WKWebview?
The following works only for the Webview URL but not XHR calls made by the site hosted in the WKWebView.
[Export("webView:decidePolicyForNavigationAction:decisionHandler:")]
public override void DecidePolicy(WKWebView webView, WKNavigationAction navigationAction, Action<WKNavigationActionPolicy> decisionHandler)
{
if (Reference == null || !Reference.TryGetTarget(out FormsWebViewRenderer renderer)) return;
if (renderer.Element == null) return;
var response = renderer.Element.HandleNavigationStartRequest(navigationAction.Request.Url.ToString());
if (response.Cancel || response.OffloadOntoDevice)
{
if (response.OffloadOntoDevice)
AttemptOpenCustomUrlScheme(navigationAction.Request.Url);
decisionHandler(WKNavigationActionPolicy.Cancel);
}
else
{
decisionHandler(WKNavigationActionPolicy.Allow);
renderer.Element.Navigating = true;
}
}
I found that WKURLSchemeHandler may help but i don't understand how to use it.
Can someone please help with that?