I'm trying to modify the request body of a request to show the research tool in Google docs. I'm able to trigger on each request that matches, and pull the form_data request body, but I don't see any way of modifying the request body and passing it on. All I need to do is change docs-show_reference to false.
Blocking the request doesn't work, as the page then initiates the request again, leading to a loop. I can't seem to modify the request headers properly to block the request, as the only thing that needs to change is within the form_data request body. It also doesn't appear that it's at all possible to return modified request body through chrome.webRequest
The extension also blocks all non-docs addresses (which is also working).
Here's the code I'm using (that initiates the redirect loop). All the permissions and config in manifest.json is also working properly.
chrome.webRequest.onBeforeRequest.addListener(
function(info) {
var request = info.requestBody;
if (info.url.indexOf(chrome.runtime.id) > -1) {
console.log("popup: %s",info.url);
return;
}
if (info.url.indexOf("docs.google.com") > -1){
if (request && request.formData && request.formData.preferences && request.formData.preferences[0] == '{"docs-show_reference":true}') {
return {cancel:true};
} else {
return {cancel:false};
}
}
if (info.url.indexOf('gstatic') > -1) {
return {cancel:false};
}
console.log("blocked: %s",info.url);
return {redirectUrl:chrome.extension.getURL("blocked.png")};
},
// filters
{
urls: [
"<all_urls>"
]
},
// extraInfoSpec
["blocking", "requestBody"]
);
According to Issue 91191, we can't modify form data in chrome extension now.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With