如何在chrome扩展中获取发布数据

adn*_*ili 8 javascript post google-chrome google-chrome-extension

我试图在简单的chrome扩展中发布数据,但它不起作用:

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"]);
Run Code Online (Sandbox Code Playgroud)

我正在使用此站点来测试扩展名:

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

小智 14

我知道这是很久以前问过的,但是如果有其他人遇到同样的问题,我找到了答案.

当支持查看POST数据的唯一侦听器是onBeforeRequest时,您正在使用侦听onBeforeSendHeaders.但是,您还需要向.addListener的第三个参数提供extraInfoSpec "requestBody" .一个例子如下.

/* 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"]
);
Run Code Online (Sandbox Code Playgroud)