Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to modify request bodies by chrome extension

I've tried use chrome.webRequest API and finally found out that it looks like google don't allow us to modify requestBodies of POST requests? I could only cancel it or modify its headers. So is there any other way to modify the raw (not form) body of a post request? I know that a proxy server could do that but I want to deal with it using extension.

like image 212
Frank Xu Avatar asked Aug 06 '16 05:08

Frank Xu


2 Answers

This works for some cases: first, save the body of the request in a variable in the onBeforeRequest listener. Then, in onBeforeSendHeaders you can either cancel or redirect the original request (sorry, Chrome gives you only two options to deal with the original). Also in onBeforeSendHeaders, you issue a new request (say, jquery ajax) to which you attach the old body from the variable, and the old headers - both can be modified/rewritten as needed. (Minor catch: it won't let you set all of the headers for "security reasons", so you may add one more onBeforeSendHeaders listener to add the sensitive headers to the new request as well).

Works for cases when the request issuer is happy with a redirect or cancel as a response. If the request issuer expects the full actual response, intact, with no redirects, then it gets harder.

like image 123
twelve40 Avatar answered Sep 18 '22 18:09

twelve40


Chrome extension Netify allows request modification, including POST body

like image 38
michaldo Avatar answered Sep 18 '22 18:09

michaldo