Wednesday, July 1, 2026
HomeiOS Developmentintercept a GET ajax request from javascript in iOS wkWebView (utilizing objective-c)

intercept a GET ajax request from javascript in iOS wkWebView (utilizing objective-c)

[ad_1]

I’ve a hybrid app that runs on iOS, and makes use of wkWebView (the language is goal c).
I’m making an attempt to intercept a GET request from the javascript facet, within the iOS wkWebView facet.
In javascript, I make a fetch, or xhr request name, however it’s not intercepted in wkWebView.
(An equal model of the app that runs on Android, and makes use of webView works okay – the fetch request, is intercepted in webView by way of shouldInterceptRequest.)

If I do a window.location.href name, the decision is intercepted (in decidePolicyForNavigationAction) (however this isn’t a request).
But when I do fetch or xhr (XMLHttpRequest) request, the decision is NOT intercepted.

A number of questions on the Web like this ask about learn how to intercept POST requests.
My case is much more primary. I can’t intercept a GET request

My code appears to be like like this:

Javascript code:

let url="http://instance.com";

// try3 - utilizing href - name is intercepted in iOS (however this isn't a request...)
window.location.href = url;

# --------------------------------------------------------------

// try2 - utilizing xhr - name is NOT intercepted in iOS
operate makeRequest (methodology, url, carried out) {
    var xhr = new XMLHttpRequest();
    xhr.open(methodology, url);
    xhr.onload = operate () {
        carried out(null, xhr.response);
    };
    xhr.onerror = operate () {
        carried out(xhr.response);
    };
    xhr.ship();
}

makeRequest('GET', url, operate (err, datums) {
    if (err) { throw err; }
    console.log(datums);
});

# --------------------------------------------------------------

// try1 - utilizing fetch - name is NOT intercepted in iOS
response = await fetch(url);

native Goal-C code:

- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
  
    DTLogDebug (@"BEG decidePolicyForNavigationAction");
    ... 

How can iOS intercept xhr ajax requests?

Thanks

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments