I am trying to get post data in a simple chrome extension, but it doesn't work:
chrome.webRequest.onBeforeSendHeaders.addListener(
function(details) {
if (details.method == "POST") {
var postData=details.requestBody.raw;
console.log(postData);
}
return {requestHeaders: details.requestHeaders};
},
{urls: ["<all_urls>"]},
["blocking", "requestHeaders"]);
I am using this site to test the extension:
https://mobile.onlinesbi.com/sbidownloader/DownloadApplication.action
I know this was asked so long ago, but in case anyone else comes across this same problem, I found the answer.
You're using the listener onBeforeSendHeaders, when the only listener that supports viewing the POST data is onBeforeRequest. However, you also need to supply an extraInfoSpec of "requestBody" to the third argument of .addListener. An example is below.
/* The Web Request API */
const WEB_REQUEST = chrome.webRequest;
WEB_REQUEST.onBeforeRequest.addListener(
function(details) {
if(details.method == "POST")
console.log(JSON.stringify(details));
},
{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