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

194
Visualizações
Intercepción de la función Fetch - Encabezados de solicitud

Estoy interceptando una recuperación ya interceptada y no puedo leer los datos de la solicitud final (específicamente los encabezados de solicitud).

Al interceptar me refiero a envolver window.fetch() original

Vea los comentarios a continuación.

 // this was already wrapped before me... // so it's NOT pure window.fetch const originalFetch = window.fetch; window.fetch = function() { // this will be added to the request arguments[1].headers.append("X-Security-A", 1); // After apply() below, the arguments are changed using // other external functions, which also intercept the fetch // and they will add additional headers; // I don't have access to these functions. // I cannot change the resource URL, because the external // functions check it. // I need to read the new headers, but the [arguments] // remain unchanged. They are changed somewhere within this apply() var promise = originalFetch.apply(this, arguments); // this will be added, but will NOT be added to actual // request, which already happened arguments[1].headers.append("X-Security-B", 1); promise.then((response) => { // Here I will get the results, but the request headers // are still NOT here; // only the ones I added // If I look in Chrome Console the sent request // contains all the headers I need to see. // HOW CAN I GET THE REQUEST HEADERS HERE? console.log('XXX Promise', promise); console.log('XXX Headers ', Array.from(arguments[1].headers.entries())); console.log('XXX Response', response); return response; }); return promise; }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

De acuerdo, una vez que window.Fetch se ajusta por segunda vez, no puede obtener los últimos argumentos antes de la solicitud real.

Sería perfecto poder hacer la primera envoltura, pero mi script se ejecuta como el último.

Sin embargo, es posible interceptar el prototipo. llamada () y el prototipo. aplicar () y eso funcionó para mí :)

 const originalFetch = window.fetch; const originalCall = window.Function.prototype.call; window.fetch = function() { var lastCall; window.Function.prototype.call = function(){ lastCall = arguments; return originalCall.apply(this, arguments); }; var x = originalFetch.apply(this, arguments); window.Function.prototype.call = originalCall; // reset x.then((response) => { console.log("XXX intercepted:", lastCall, response); return response; }); return x; };
about 4 years ago · Juan Pablo Isaza Relatório
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