Dubue
Dubue

Reputation: 11

WebExtension redirect and block websites

I have started simple web extension for firefox which in theory should block access to specific websites based on some response from the remote server. User tries to navigate, new page will not be loaded until confirmation is not received from the remote server. Unfortunately remote "check" server is limited to a few requests in a second for each user so I can't (and it's unnecessary to) check each request made after user navigates to some page. Is there any method to listen for "real" navigation not all those requests and redirect whole tab somewhere before any requests are even made?

I've tried add-on API:

WebExtensions:

Upvotes: 1

Views: 805

Answers (1)

the8472
the8472

Reputation: 43042

"http-on-modify-request" event is fired for each request separately spamming remote check server.

that observer notification gives you a http channel, the channel has a loadInfo property, which has an externalContentPolicyType property which allows you to filter for top level document loads by matching one of the content policy constants.

WebRequest.jsm and browser.webRequest are abstractions over the http observers and provide similar functionality.

Upvotes: 2

Related Questions