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

297
Visualizações
Modify fetch response body via Chrome Extension

My goal is to intercept a fetch request, change it's response body and fulfill the request using a chrome extension. I am using the following code, but the request get's not fulfilled.

chrome.debugger.onEvent.addListener(async (source, method, params: any) => {
if (method == "Fetch.requestPaused") {
  const requestId = params.requestId
  const request = params.request

  if (params.request.url.includes("myPage.html")) {
    console.log("Intercepting request " + requestId)
    chrome.debugger.sendCommand(
      { tabId: tabId },
      "Fetch.getResponseBody",
      {
        requestId: requestId,
      },
      (response: any) => {
        const responseCode = params.responseCode
        const responseHeaders = params.responseHeaders
        if (response.base64Encoded) {
          let responseBody = atob(response.body)

          // modify response body string

          chrome.debugger.sendCommand({ tabId: tabId }, "Fetch.fulfillRequest", {
            requestId: requestId,
            responseCody: responseCode,
            responseHeaders: responseHeaders,
            body: btoa(responseBody),
          })
        } else {
          chrome.debugger.sendCommand({ tabId: tabId }, "Fetch.continueRequest", { requestId: requestId })
        }
      },
    )
  } else {
    chrome.debugger.sendCommand({ tabId: tabId }, "Fetch.continueRequest", { requestId: requestId })
  }
}
})

The interception, reading, modifying and encoding the body works fine, but the request won't get fulfilled.

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