1

I would like to make a Chrome extension to edit specific values in form data. This is my current code for background.js:

chrome.webRequest.onBeforeRequest.addListener(
  function(details) {
    if(details.method == "POST") {
      let formData = details.requestBody.formData;
      if(formData) {
        Object.keys(formData).forEach(key => {
          formData[key].forEach(value => {
            if(key.includes("name")) {
              formData.name = "John";
              details.requestBody.formData = formData;
            }
          });
        });
      }
    }
    return {details: details};
  },
  {urls: ["<all_urls>"]},
  ["requestBody"]
);

When I tried to debug it I came to conclusion that the extension can successfully edit formData, but the server will still receive the unedited formData. I think the problem might be with returning details.

Zwedgy
  • 320
  • 2
  • 3
  • 17
  • 1
    Not implemented, see https://crbug.com/91191. You'll have to spoof XHR/fetch in the [page context](https://stackoverflow.com/a/9517879). – wOxxOm Jul 24 '18 at 10:51
  • How could I do that. I've looked at many examples none seem to work. @wOxxOm – Zwedgy Jul 25 '18 at 19:24
  • Use any example that overrides XMLHttpRequest and put that code in a script element as shown in the answer I've linked. – wOxxOm Jul 25 '18 at 19:29

0 Answers0