Search code examples
javascriptfirefoxfirefox-addonmozillafirefox-addon-webextensions

Firefox WebExtensions: can not get canceled request data


During playing with Firefox WebExtensions I've created a simple add-on that cancels certain POST request and reads its params:

manifest.json

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

  "permissions": [
    "webRequest",
    "webRequestBlocking",
    "http://kamil.hism.ru/pocs/*"
  ],

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

background.js

var pattern = "http://kamil.hism.ru/pocs/simple_form_action";

function cancel(requestDetails) {
  console.log("Canceling: " + requestDetails.url);
  console.log(requestDetails.requestBody.formData.some_field)
  // debugger
  return { cancel: true };
}

browser.webRequest.onBeforeRequest.addListener(
  cancel,
  { urls:[pattern] },
  ["requestBody", "blocking"]
);

The target page with form is located here: http://kamil.hism.ru/pocs/simple_form.html

requestDetails contains requestBody that should contain formData object with all passed data. In Chrome it works good, but in Firefox requestBody contains only raw array with an ArrayBuffer object. I've tried to convert it to string using String.fromCharCode.apply(null, new Uint16Array(requestDetails.requestBody.raw[0]));, but it returns empty string.

So, the question is: does anybody know how to solve that problem and get all data from canceled request using Firefox WebExtension add-on? Maybe it's some bug in Mozilla's implementation of WebExtensions?


Solution

  • With the help of Mozilla community it turned out this is actually a bug in Firefox WebExtensions. Although I couldn't find the exact release note or bug in bugzilla related to it, Firefox Nightly build (53.0a) doesn't have this issue:

    enter image description here

    Hopefully soon those changes from Nightly would be merged into Release channel.