How to change request body using chrome extension

I tried using the chrome.webRequest API and finally found out that it looks like google is not allowing us to modify the requestBodies of POST requests? I could only undo it or change its headers. So is there any other way to change the original (not the form) body of the mail request? I know that a proxy server can do this, but I want to deal with it with an extension.

+4
source share
1 answer

This works in some cases: first, save the request body in a variable in the listener onBeforeRequest. Then in onBeforeSendHeadersyou can either cancel or redirect the original request (sorry, Chrome gives you only two options for working with the original). Also in onBeforeSendHeadersyou issue a new query (say, jquery ajax) to which you attach the old body from the variable, and the old headers - both of which can be changed / rewritten as needed. (Minor catch: it will not allow you to set all the headers for "security reasons", so you can add another listener onBeforeSendHeadersto add sensitive headers to the new request).

, . , , , .

0

Source: https://habr.com/ru/post/1650389/


All Articles