Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

301
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!