Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

440
Views
How to intercept a GET ajax request from javascript in iOS wkWebView (using objective-c)

I have a hybrid app that runs on iOS, and uses wkWebView (the language is objective c).
I am trying to intercept a GET request from the javascript side, in the iOS wkWebView side.
In javascript, I make a fetch, or xhr request call, but it is not intercepted in wkWebView.
(An equivalent version of the app that runs on Android, and uses webView works ok - the fetch request, is intercepted in webView via shouldInterceptRequest.)

If I do a window.location.href call, the call is intercepted (in decidePolicyForNavigationAction) (but this is not a request).
But if I do fetch or xhr (XMLHttpRequest) request, the call is NOT intercepted.

Several questions on the Internet like this ask about how to intercept POST requests.
My case is even more basic. I cannot intercept a GET request

My code looks like this:

Javascript code:

let url = 'http://example.com';

// try3 - using href - call is intercepted in iOS (but this is not a request...)
window.location.href = url;

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

// try2 - using xhr - call is NOT intercepted in iOS
function makeRequest (method, url, done) {
    var xhr = new XMLHttpRequest();
    xhr.open(method, url);
    xhr.onload = function () {
        done(null, xhr.response);
    };
    xhr.onerror = function () {
        done(xhr.response);
    };
    xhr.send();
}

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

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

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

native Objective-C code:

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

How can iOS intercept xhr ajax requests?

Thanks

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!