While playing with Firefox WebExtensions, I created a simple add-in that cancels a specific POST request and reads its parameters:
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 landing page with the form is here: http://kamil.hism.ru/pocs/simple_form.html
requestDetails contains requestBody , which should contain a formData object with all the data passed. In Chrome, this works well, but in Firefox requestBody only contains a raw array with an ArrayBuffer object. I tried converting it to a string using String.fromCharCode.apply(null, new Uint16Array(requestDetails.requestBody.raw[0])); but it returns an empty string.
So the question is: does anyone know how to solve this problem and get all the data from a canceled request using the Firefox WebExtension add-on? Maybe this is a bug in the implementation of WebExtensions Mozilla?
source share