Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

441
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda