How to get message data in chrome extension

I am trying to get post data in a simple chrome extension, but it does not 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 use this site to check the extension:

https://mobile.onlinesbi.com/sbidownloader/DownloadApplication.action

+6
source share
1 answer

I know that this was asked so long ago, but in case someone else runs into this problem, I found the answer.

You use the onBeforeSendHeaders listener when the only listener that supports viewing POST data is onBeforeRequest . However, you also need to provide extraInfoSpec "requestBody" for the third argument .addListener . The following is an example.

 /* 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"] ); 
+9
source

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


All Articles