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:
.action
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./sbidownloader/DownloadApplication.action
Share Improve this question asked Sep 8, 2013 at 6:38 adnan kamiliadnan kamili 9,4659 gold badges73 silver badges133 bronze badges 1- 1 possible duplicate of Chrome.webRequest API - requestBody always undefined – Rob W Commented Sep 8, 2013 at 8:48
1 Answer
Reset to default 16I know this was asked so long ago, but in case anyone else es 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"]
);