mirror of
https://github.com/mdn/webextensions-examples.git
synced 2026-04-17 14:59:12 +02:00
Add proxy example (#225)
* Add proxy example * Updated after review comments
This commit is contained in:
21
proxy-blocker/proxy/proxy-script.js
Normal file
21
proxy-blocker/proxy/proxy-script.js
Normal file
@@ -0,0 +1,21 @@
|
||||
var blockedHosts = [];
|
||||
const allow = "DIRECT 1234";
|
||||
const deny = "PROXY 127.0.0.1:65535";
|
||||
|
||||
// tell the background script that we are ready
|
||||
browser.runtime.sendMessage("init");
|
||||
|
||||
// listen for updates to the blocked host list
|
||||
browser.runtime.onMessage.addListener((message) => {
|
||||
blockedHosts = message;
|
||||
});
|
||||
|
||||
// required PAC function that will be called to determine
|
||||
// if a proxy should be used.
|
||||
function FindProxyForURL(url, host) {
|
||||
if (blockedHosts.indexOf(host) != -1) {
|
||||
browser.runtime.sendMessage(`Proxy-blocker: blocked ${url}`);
|
||||
return deny;
|
||||
}
|
||||
return allow;
|
||||
}
|
||||
Reference in New Issue
Block a user