Javascript - Chrome 扩展 - Webrequest - Responsebody

Javascript - Chrome extension - Webrequest - Responsebody

我想为 Chrome 写一个扩展来观看我的 XHR 调用,我发现我必须为此使用 webRequest。

我想获取请求的响应正文,但我一直找不到如何执行此操作。这可能吗?

// chrome.browserAction.onClicked.addListener(function (tab) {
    var callback = function(details) {
        var url = details.url;

        console.log(details);
    };

    var filter = {
        urls: ["*://safan.dev/*"]
    };

    var ops = ["requestBody"];

    chrome.webRequest.onBeforeRequest.addListener(
        callback, filter, ops
    );
// });

并显示:

{
  "manifest_version": 2,

  "name": "Forge of Empires",
  "description": "FOE",
  "version": "1.0",

  "browser_action": {
    "default_icon": "icon.png"
  },
  "permissions": [
    "webRequest",
    "<all_urls>"
  ],
  "background": {
    "scripts": ["logic.js"]
  }
}

I want to get the response-body of the request but i never can find how to do this. Is this possible?

暂时没有。有个long-standing feature request.


请注意,您可以使用 devtools.network API (requires Dev Tools to be open) or Debugger API(需要关闭 Dev Tools,低级别)。