Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript - Chrome extension - Webrequest - Responsebody

I want to write an extension for Chrome to watch my XHR calls and I found that i have to use webRequest for this.

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

// 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
    );
// });

And manifest:

{
  "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"]
  }
}
like image 932
Wim te Groen Avatar asked Jul 06 '16 10:07

Wim te Groen


People also ask

How do I view body responses in Chrome?

To view the response body to a request: Click the URL of the request, under the Name column of the Requests table. Click the Response tab.

Can I use webRequest?

To use the webRequest API for a given host, an extension must have the "webRequest" API permission and the host permission for that host. To use the "blocking" feature, the extension must also have the "webRequestBlocking" API permission.


1 Answers

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

Not at the moment. There is a long-standing feature request.


Note that you can do it using devtools.network API (requires Dev Tools to be open) or Debugger API (requires Dev Tools to be closed, low-level).

like image 152
Xan Avatar answered Oct 27 '22 03:10

Xan