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

303
Vistas
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 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