WebExtensions: can not get canceled request data

Hello!

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?

Thanks.

P.S.
This question was originally posted on stackoverflow, but I didn’t get any answer there :confused:

1 Like

Thanks for supplying a minimal reproducible example!

I asked about this in the mailing list, and got this answer: https://mail.mozilla.org/pipermail/dev-addons/2017-January/002463.html.

So it’s probably best to file a bug.

@wbamberg, thank you for your message!

I’ve just checked latest Firefox Nightly build (53.0a) and this issue is not presented there:

Although I couldn’t find the exact release note or bug related to it, but hopefully soon those changes from Nightly would be merged into Release channel :slight_smile: