Integrated proxy.onRequest functionality
This commit is contained in:
parent
78330a4d20
commit
790a9273f9
3 changed files with 31 additions and 4 deletions
|
@ -117,6 +117,16 @@ const assignManager = {
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async handleProxifiedRequest(requestInfo) {
|
||||||
|
if(requestInfo.tabId === -1)
|
||||||
|
return {type: "direct"};
|
||||||
|
|
||||||
|
var tab = await browser.tabs.get(requestInfo.tabId);
|
||||||
|
var proxy = await window.proxifiedContainers.retrieveFromBackground(tab.cookieStoreId);
|
||||||
|
|
||||||
|
return proxy;
|
||||||
|
},
|
||||||
|
|
||||||
// Before a request is handled by the browser we decide if we should route through a different container
|
// Before a request is handled by the browser we decide if we should route through a different container
|
||||||
async onBeforeRequest(options) {
|
async onBeforeRequest(options) {
|
||||||
if (options.frameId !== 0 || options.tabId === -1) {
|
if (options.frameId !== 0 || options.tabId === -1) {
|
||||||
|
@ -224,6 +234,10 @@ const assignManager = {
|
||||||
this._onClickedHandler(info, tab);
|
this._onClickedHandler(info, tab);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Before anything happens we decide if the request should be proxified
|
||||||
|
browser.extension.getBackgroundPage().console.log('[SAMUEL CODE] Adding proxy.onRequest listener');
|
||||||
|
browser.proxy.onRequest.addListener(this.handleProxifiedRequest, {urls: ["<all_urls>"]});
|
||||||
|
|
||||||
// Before a request is handled by the browser we decide if we should route through a different container
|
// Before a request is handled by the browser we decide if we should route through a different container
|
||||||
this.canceledRequests = {};
|
this.canceledRequests = {};
|
||||||
browser.webRequest.onBeforeRequest.addListener((options) => {
|
browser.webRequest.onBeforeRequest.addListener((options) => {
|
||||||
|
|
|
@ -1,5 +1,17 @@
|
||||||
//This object allows other scripts to access the list mapping containers to their proxies
|
//This object allows other scripts to access the list mapping containers to their proxies
|
||||||
window.proxifiedContainers = {
|
window.proxifiedContainers = {
|
||||||
|
|
||||||
|
//Slightly modified version of 'retrieve' which returns a direct proxy whenever an error is met.
|
||||||
|
retrieveFromBackground: function(cookieStoreId = null) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
window.proxifiedContainers.retrieve(cookieStoreId).then((success) => {
|
||||||
|
resolve(success.proxy);
|
||||||
|
}, (error) => {
|
||||||
|
resolve({type: "direct"});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
//Resolves to a proxy object which can be used in the return of the listener required for browser.proxy.onRequest.addListener
|
//Resolves to a proxy object which can be used in the return of the listener required for browser.proxy.onRequest.addListener
|
||||||
retrieve: function(cookieStoreId = null) {
|
retrieve: function(cookieStoreId = null) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
@ -15,10 +27,10 @@ window.proxifiedContainers = {
|
||||||
if (Object.getOwnPropertyNames(results).length == 0) {
|
if (Object.getOwnPropertyNames(results).length == 0) {
|
||||||
reject({error: "uninitialized", message: ""});
|
reject({error: "uninitialized", message: ""});
|
||||||
}
|
}
|
||||||
|
|
||||||
else if(cookieStoreId == null) {
|
else if(cookieStoreId == null) {
|
||||||
resolve(results_array);
|
resolve(results_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
else {
|
else {
|
||||||
|
@ -57,7 +69,7 @@ window.proxifiedContainers = {
|
||||||
{
|
{
|
||||||
proxifiedContainersStore[index] = {cookieStoreId: cookieStoreId, proxy: proxy};
|
proxifiedContainersStore[index] = {cookieStoreId: cookieStoreId, proxy: proxy};
|
||||||
}
|
}
|
||||||
|
|
||||||
browser.storage.local.set({proxifiedContainersKey: proxifiedContainersStore});
|
browser.storage.local.set({proxifiedContainersKey: proxifiedContainersStore});
|
||||||
resolve(proxifiedContainersStore[index]);
|
resolve(proxifiedContainersStore[index]);
|
||||||
}, (errorObj) => {
|
}, (errorObj) => {
|
||||||
|
|
|
@ -30,7 +30,8 @@
|
||||||
"storage",
|
"storage",
|
||||||
"tabs",
|
"tabs",
|
||||||
"webRequestBlocking",
|
"webRequestBlocking",
|
||||||
"webRequest"
|
"webRequest",
|
||||||
|
"proxy"
|
||||||
],
|
],
|
||||||
|
|
||||||
"commands": {
|
"commands": {
|
||||||
|
|
Loading…
Add table
Reference in a new issue