chrome.webrequest.onbeforerequest.addlistener for Firefox?
This question was asked for a very long time. I'm not sure if there was solution for this at then. But now we can do such things using Firefox WebExtensions API.
It is compatible with Chrome in most APIs (though some of them are not supported, or not fully supported).
For this very specific question, Firefox WebExtensions support webRequest API, you can use it like the way in Chrome:
chrome.webRequest.onBeforeRequest.addListener(...);
Note: To use
webRequest
API, you must have thewebRequest
permission in your manifest.json.
You can use the same request format using browser
namespace. Below is a sample code for the same. Here listener
is a callback function.
browser.webRequest.onBeforeRequest.addListener( listener, // function filter // object)browser.webRequest.onBeforeRequest.removeListener(listener)browser.webRequest.onBeforeRequest.hasListener(listener)
You can find more details about this api here.
Anything that we can show you will be disabled at an unknown time and would not work for webextensions, due to Kev Needham's plan for the future of Firefox extensions so all that you can do is wait until webextensions are finally supported by Firefox.