I'm aware that chrome.webRequest.onBeforeRequest
allows a request to be intercepted, analyzed and blocked, but it only allows access to the request headers, and not the request body (as far as i know).
Sample use case: think intercepting form values.
It seems there is a API change proposal here suggesting exactly this.
Is there another way this could be accomplished?
Thanks.
This functionality has been added to the API now, see the documentation.
In order to access the body you need to do the following:
chrome.webRequest.onBeforeRequest.addListener( function(details) { console.log(details.requestBody); }, {urls: ["https://myurlhere.com/*"]}, ['requestBody'] );
Here is what I did
requestBody
to get the post requests body decoder
the parse the body into a string Here is an example
chrome.webRequest.onBeforeRequest.addListener( function(details) { if(details.method == "POST") // Use this to decode the body of your post var postedString = decodeURIComponent(String.fromCharCode.apply(null, new Uint8Array(details.requestBody.raw[0].bytes))); console.log(postedString) }, {urls: ["<all_urls>"]}, ["blocking", "requestBody"] );
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