Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How get raw response body inside a Web Extension for Firefox 55?

I try to get the raw response body inside a Web Extension using Firefox 55.0.3.

Only "solutions" I have seen for now:

  • Repeat the request (I absolutly don't want to repeat the request)
  • Using Javascript to get innerHTML attribute of HTML tags such as head and body (tell me if I'm wrong, but with a solution like that I will not always have the whole content, for example I will get nothing in case of response without HTML. So it will never be the real raw response and in some case it will simply not work.)

Also, I saw this answer for Chrome (from 2015) using the debugger, but I wasn't able to do it with Firefox. This kind of solutions are interesting, I read Mozilla documentation about devtools but I didn't find a way of using the network tab of webtools interface with Javascript inside a Web Extension.

To give you more details, my goal is to intercept the full request and response from server (header and body). This is not a problem to do it, except for the response body.

Here an example of code to get the request body: (background script)

browser.webRequest.onBeforeRequest.addListener(
    function (e) {
        console.log(e);
    },
    {urls: ["http://*/*", "https://*/*"]},
    ["requestBody"]
)

Here some documentations that I used (there is more, but these links are all official):

  • Mozilla documentation about Web Extension
    • Intercept HTTP requests
    • webRequest
    • webRequest.onHeadersReceived
    • webRequest.onBeforeRequest
    • webRequest.onBeforeSendHeaders

Here some examples of Web Extensions.

Any ideas, solutions or even explainations "why this is not possible" are welcome, thank you in advance for your time !

Cheers++

like image 916
Benoît Zu Avatar asked Sep 21 '17 08:09

Benoît Zu


People also ask

How do I add unpacked Extensions to Firefox?

In Firefox: Open the about:debugging page, click the This Firefox option, click the Load Temporary Add-on button, then select any file in your extension's directory. The extension now installs, and remains installed until you restart Firefox.


1 Answers

This is now available, as of Firefox 57: browser.webRequest.filterResponseData allows you to add a listener via browser.webRequest.onBeforeRequest which receives, and allows you to modify the response.

You can see an example in the Mozilla github webextensions-examples repo

like image 181
410 gone Avatar answered Nov 09 '22 15:11

410 gone