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?
firefox
browser version do you use? – Tarncontent header
and set it toContent-Type: text/html; charset=utf-8
by using the following here – Tarn