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
.