(Firefox Addon) 如何通过 onBeforeRequest 访问拦截请求的正文

时间:2021-07-09 01:09:43

标签: firefox firefox-addon

我正在尝试使用插件拦截并记录在 Firefox 中发出的 POST 请求的正文。我用过这个清单

{
"description": "Demonstrating webRequests",
"manifest_version": 2,
"name": "webRequest-demo",
"version": "1.0",

"permissions": [
  "webRequest",
  "webRequestBlocking",
  "<all_urls>"
],

"background": {
  "scripts": ["background.js"]
}
}

对 onBeforeRequest 的调用

browser.webRequest.onBeforeRequest.addListener(
    logURL,
    {urls: ["<all_urls>"]},
    ["blocking", "requestBody"]
);

和一个非常基本的处理程序 logURL

function logURL(requestDetails) {
if(requestDetails.url === "https://www.google.com/")
{
    console.log(requestDetails);
    var postedString = decodeURIComponent(String.fromCharCode.apply(null,
        new Uint8Array(requestDetails.requestBody.raw[0].bytes)));
    console.warn(postedString);
}}

然而,虽然第一个日志工作正常,秒打印错误“类型错误:无法访问死对象”。我知道这是新的 Firefox 的内存管理,但它基本上阻止了对该变量的每次访问。

我尝试了很多日志(这是最新的),但它们要么打印了一些无用的数据,例如“bytes: ArrayBuffer { byteLength: 65 }”,或者只是那个“死对象”的东西

我已经确定请求有一个帖子正文(它甚至显示在开发控制台中)

谢谢

0 个答案:

没有答案