如何从请求中的原始字节解码JSON有效负载?

时间:2019-04-06 14:09:12

标签: javascript json google-chrome-extension

我正在尝试拦截页面中发出的POST请求,并使用Content-Type: application/json读取其有效负载。但是,使用chrome.webRequest捕获的有效负载为空。我认为这是因为json有效负载位于raw中,我无法解析

background.js用于向内容发送请求

chrome.webRequest.onBeforeRequest.addListener(
    function(details)
    {
        chrome.tabs.query({currentWindow: true, active: true},
            function(tabs) {
                chrome.tabs.sendMessage(tabs[0].id, details)
            })
    },
    {urls: ["<all_urls>"]},
    ['requestBody']
);

在调试器中,请求看起来像这样-

request:
 frameId: 0
 initiator: "https://somewebsite.com"
 method: "POST"
 parentFrameId: -1
 requestBody:
  raw: Array(1)
   0:
    bytes: {}
requestId: "101041"
tabId: 597
timeStamp: 1554556743661.0898
type: "xmlhttprequest"

我不确定如何从原始字节中检索JSON有效负载吗?

0 个答案:

没有答案
相关问题