Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

443
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda