Firefox WebExtensions: Cannot Cancel Request Data

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?

+5
source share
1 answer

Using the help of the Mozilla community, it turned out that this is actually a bug in Firefox WebExtensions. Although I could not find the exact release note or bug in bugzilla related to it, Firefox Nightly build (53.0a) does not have this problem :

enter image description here

Most likely, these changes from Nightly will be merged into the Release channel.

+1
source

Source: https://habr.com/ru/post/1262459/


All Articles