Fixed problem where creating a new container did not correctly associate the proxy entered with it
This commit is contained in:
parent
0a864f0cf3
commit
34bde83067
3 changed files with 41 additions and 8 deletions
|
@ -46,6 +46,11 @@ const backgroundLogic = {
|
||||||
window.proxifiedContainers.set(this.cookieStoreId(options.userContextId), options.proxy);
|
window.proxifiedContainers.set(this.cookieStoreId(options.userContextId), options.proxy);
|
||||||
} else {
|
} else {
|
||||||
donePromise = browser.contextualIdentities.create(options.params);
|
donePromise = browser.contextualIdentities.create(options.params);
|
||||||
|
|
||||||
|
//We cannot yet access the new cookieStoreId via this.cookieStoreId(...), so we take this from the resolved promise
|
||||||
|
donePromise.then((identity) => {
|
||||||
|
window.proxifiedContainers.set(identity.cookieStoreId, options.proxy);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
await donePromise;
|
await donePromise;
|
||||||
browser.runtime.sendMessage({
|
browser.runtime.sendMessage({
|
||||||
|
|
|
@ -1069,6 +1069,9 @@ Logic.registerPanel(P_CONTAINER_EDIT, {
|
||||||
iconInput.checked = iconInput.value === identity.icon;
|
iconInput.checked = iconInput.value === identity.icon;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//Clear the proxy field before doing the retrieval requests below
|
||||||
|
document.querySelector("#edit-container-panel-proxy").value = "";
|
||||||
|
|
||||||
const edit_proxy_dom = function(result) {
|
const edit_proxy_dom = function(result) {
|
||||||
if(result.type === "http")
|
if(result.type === "http")
|
||||||
document.querySelector("#edit-container-panel-proxy").value = result.host.toString() + ":" + result.port.toString();
|
document.querySelector("#edit-container-panel-proxy").value = result.host.toString() + ":" + result.port.toString();
|
||||||
|
@ -1083,18 +1086,18 @@ Logic.registerPanel(P_CONTAINER_EDIT, {
|
||||||
}, (error) => {
|
}, (error) => {
|
||||||
if(error.error === "uninitialized" || error.error === "doesnotexist") {
|
if(error.error === "uninitialized" || error.error === "doesnotexist") {
|
||||||
window.proxifiedContainers.set(identity.cookieStoreId, DEFAULT_PROXY, error.error === "uninitialized").then((result) => {
|
window.proxifiedContainers.set(identity.cookieStoreId, DEFAULT_PROXY, error.error === "uninitialized").then((result) => {
|
||||||
edit_proxy_dom(result.proxy);
|
edit_proxy_dom(result);
|
||||||
}, (error) => {
|
}, (error) => {
|
||||||
window.proxifiedContainers.report_proxy_error(error, "popup.js: occurence 1");
|
window.proxifiedContainers.report_proxy_error(error, "popup.js: error 1");
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
window.proxifiedContainers.report_proxy_error(error, "popup.js: occurence 2");
|
window.proxifiedContainers.report_proxy_error(error, "popup.js: error 2");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
window.proxifiedContainers.report_proxy_error(error, "popup.js: occurence 3");
|
window.proxifiedContainers.report_proxy_error(error, "popup.js: error 3");
|
||||||
}
|
}
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
window.proxifiedContainers.report_proxy_error(err, "popup.js: occurence 4");
|
window.proxifiedContainers.report_proxy_error(err, "popup.js: error 4");
|
||||||
});
|
});
|
||||||
|
|
||||||
return Promise.resolve(null);
|
return Promise.resolve(null);
|
||||||
|
|
|
@ -1,3 +1,20 @@
|
||||||
|
//Below lets us print errors, huge thanks to Jonothan @ https://stackoverflow.com/questions/18391212/is-it-not-possible-to-stringify-an-error-using-json-stringify
|
||||||
|
if (!('toJSON' in Error.prototype))
|
||||||
|
Object.defineProperty(Error.prototype, 'toJSON', {
|
||||||
|
value: function () {
|
||||||
|
var alt = {};
|
||||||
|
|
||||||
|
Object.getOwnPropertyNames(this).forEach(function (key) {
|
||||||
|
alt[key] = this[key];
|
||||||
|
}, this);
|
||||||
|
|
||||||
|
return alt;
|
||||||
|
},
|
||||||
|
configurable: true,
|
||||||
|
writable: true
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
//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 = {
|
||||||
|
|
||||||
|
@ -60,7 +77,7 @@ window.proxifiedContainers = {
|
||||||
message: error
|
message: error
|
||||||
});
|
});
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
window.proxifiedContainers.report_proxy_error(error, "5");
|
window.proxifiedContainers.report_proxy_error(error, "proxified-containers.js: error 1");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -68,15 +85,22 @@ window.proxifiedContainers = {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (initialize === true) {
|
if (initialize === true) {
|
||||||
const proxifiedContainersStore = [];
|
const proxifiedContainersStore = [];
|
||||||
|
proxifiedContainersStore.push({
|
||||||
|
cookieStoreId: cookieStoreId,
|
||||||
|
proxy: proxy
|
||||||
|
});
|
||||||
|
|
||||||
browser.storage.local.set({
|
browser.storage.local.set({
|
||||||
proxifiedContainersKey: proxifiedContainersStore
|
proxifiedContainersKey: proxifiedContainersStore
|
||||||
});
|
});
|
||||||
|
|
||||||
|
resolve(proxy);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Assumes proxy is a properly formatted object
|
//Assumes proxy is a properly formatted object
|
||||||
window.proxifiedContainers.retrieve().then((proxifiedContainersStore) => {
|
window.proxifiedContainers.retrieve().then((proxifiedContainersStore) => {
|
||||||
|
|
||||||
let index = proxifiedContainersStore.findIndex(i => i.cookieStoreId === cookieStoreId);
|
let index = proxifiedContainersStore.findIndex(i => i.cookieStoreId === cookieStoreId);
|
||||||
|
|
||||||
if (index === -1) {
|
if (index === -1) {
|
||||||
proxifiedContainersStore.push({
|
proxifiedContainersStore.push({
|
||||||
cookieStoreId: cookieStoreId,
|
cookieStoreId: cookieStoreId,
|
||||||
|
@ -93,6 +117,7 @@ window.proxifiedContainers = {
|
||||||
browser.storage.local.set({
|
browser.storage.local.set({
|
||||||
proxifiedContainersKey: proxifiedContainersStore
|
proxifiedContainersKey: proxifiedContainersStore
|
||||||
});
|
});
|
||||||
|
|
||||||
resolve(proxifiedContainersStore[index]);
|
resolve(proxifiedContainersStore[index]);
|
||||||
}, (errorObj) => {
|
}, (errorObj) => {
|
||||||
reject(errorObj);
|
reject(errorObj);
|
||||||
|
@ -100,7 +125,7 @@ window.proxifiedContainers = {
|
||||||
throw error;
|
throw error;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
parseProxy: function(proxy_str) {
|
parseProxy: function(proxy_str) {
|
||||||
const regexp = /(\b(\w+):(\w+)@)?(((?:\d{1,3}\.){3}\d{1,3}\b)|(\b(\w+)(\.(\w+))+))(:(\d+))?/;
|
const regexp = /(\b(\w+):(\w+)@)?(((?:\d{1,3}\.){3}\d{1,3}\b)|(\b(\w+)(\.(\w+))+))(:(\d+))?/;
|
||||||
if (regexp.test(proxy_str) !== true)
|
if (regexp.test(proxy_str) !== true)
|
||||||
|
|
Loading…
Add table
Reference in a new issue