2

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?

Omtechguy
  • 3,321
  • 7
  • 37
  • 71
  • 1
    This is something I found that's relevant, but it's in Swift https://stackoverflow.com/a/28828451/11104068 – Saamer Aug 06 '19 at 14:30

0 Answers0