Firefox WebExtensions: can not get canceled request data
Asked Answered
P

1

6

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?

Prospectus answered 7/1, 2017 at 14:25 Comment(4)
which firefox browser version do you use?Tarn
@pritishvaidya the latest firefox dev edition version 52.0a2 (2017-01-09) (64-bit)Prospectus
I think you might need to modify the content header and set it to Content-Type: text/html; charset=utf-8 by using the following hereTarn
@pritishvaidya, I'm not sure it'll help since this is a bug in Mozilla's implementation of WebExtensions itself, see the answer :)Prospectus
P
1

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.

Prospectus answered 10/1, 2017 at 15:19 Comment(1)
oh ,forgot to check it .Tarn

© 2022 - 2024 — McMap. All rights reserved.