proxy-blocker updates (#422)

* proxy-blocker updates

These changes replace the use of the deprecated `proxy.register` (PAC file) with `proxy.onRequest` to handle the proxying of requests.

* Changes as per feedback

* Fixed typo

* Addressed feedback relating to issue with variable initialization after enable/disable

* Typo fix

* The changes as suggested by @wbamberg
This commit is contained in:
rebloor
2019-09-05 06:28:46 +12:00
committed by wbamberg
parent 12f59209c9
commit 72dfcf1bad
6 changed files with 78 additions and 88 deletions

View File

@@ -1,22 +1,19 @@
# proxy-filter
## What it does
This add-on registers a [PAC script](https://developer.mozilla.org/en-US/docs/Web/HTTP/Proxy_servers_and_tunneling/Proxy_Auto-Configuration_%28PAC%29_file) using the proxy API.
This extension uses the proxy API listener `onRequest` to listen for requests to visit a web page, compare the webpage's domain with a blocked host list, and proxy domains on the blocked list to 127.0.0.1.
The PAC script is initialized with a list of hostnames: it blocks requests to any hosts that are in the list.
The list of blocked domains is held in local storage and given the initial value `["example.com", "example.org"]` when the extension installs. The list can be modified through the extension"s options page.
The list is given the following default values: `["example.com", "example.org"]`, but the user can add and remove hosts using the add-on's options page.
Note that the hostname-matching is simple: hostnames must match an entry in the list if they are to be blocked. So with the default settings, "example.org" is blocked but "www.example.org" is permitted.
Note that the hostname-matching is very simple: hostnames must exactly match an entry in the list if they are to be blocked. So with the default settings, "example.org" would be blocked but "www.example.org" would be permitted.
To try it out:
To try out this extension:
* install it
* try visiting `http://example.com`, and see it is blocked
* visit `about:addons`, open the add-on's preferences, and try changing the hostnames in the text box
* try visiting some different pages, to see the effect of your changes.
* visit `http://example.com` and see it is blocked
* visit `about:addons`, open the add-on's preferences, and change the hostnames in the text box
* visit some pages to see the effect of your changes.
## What it shows
* How to implement a simple PAC script, and register it using the proxy API.
* How to exchange messages between a PAC script and a background script.
* How to implement `browser.proxy.onRequest` and proxy requests.
* How to store and retrieve lists from local storage.