chrome.webrequest.onbeforerequest.addlistener for Firefox?
P

3

9

Google Chrome contains some functionality in its chrome.webrequest API (e.g., http://developer.chrome.com/extensions/samples.html#12a7bf1490a26359eadf10917e37c5b9 ) that can be used to redirect certain URLs to a specified web page. The Chrome extension uses a blocking event listener (chrome.webRequest.onBeforeRequest.addListener) and does a redirect for targeted URLs. How might I do something similar in a FireFox Add-on?

Pontefract answered 14/6, 2013 at 16:16 Comment(3)
developer.mozilla.org/en/docs/…Encumber
@方觉 Only partially works, it fires by loading files, but subject.cancel() does stop them from loading.Puzzle
I can't get even that far with Firefox (50.0.2). I get browser.webRequest is undefined or chrome.webRequest is undefined.Quinary
R
1

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 the webRequest permission in your manifest.json.

Remission answered 11/4, 2017 at 5:7 Comment(0)
B
0

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.

Bea answered 25/9, 2018 at 10:0 Comment(0)
P
-1

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.

Papagena answered 10/11, 2015 at 18:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.