diff --git a/extensions/chromium/runet-censorship-bypass/src/extension-common/00-init-apis.js b/extensions/chromium/runet-censorship-bypass/src/extension-common/00-init-apis.js index f4529d7..e8ba9c0 100644 --- a/extensions/chromium/runet-censorship-bypass/src/extension-common/00-init-apis.js +++ b/extensions/chromium/runet-censorship-bypass/src/extension-common/00-init-apis.js @@ -41,15 +41,18 @@ console.log('Extension started.'); }, + lastError: undefined, + checkChromeError() { // Chrome API calls your cb in a context different from the point of API // method invokation. - const err = chrome.runtime.lastError || chrome.extension.lastError; + const err = chrome.runtime.lastError || chrome.extension.lastError || self.lastError; if (!err) { return; } console.warn('API returned error:', err); + delete self.lastError; return new Error(err.message); // Add stack. }, diff --git a/extensions/chromium/runet-censorship-bypass/src/extension-common/15-firefox-proxy-settings.js b/extensions/chromium/runet-censorship-bypass/src/extension-common/15-firefox-proxy-settings.js index df44df1..c0e8bbc 100644 --- a/extensions/chromium/runet-censorship-bypass/src/extension-common/15-firefox-proxy-settings.js +++ b/extensions/chromium/runet-censorship-bypass/src/extension-common/15-firefox-proxy-settings.js @@ -5,11 +5,11 @@ if (window.apis.platform.ifFirefox) { const prefix = 'firefox-only'; const ffxStorage = { - get(keys) { + get(key) { return new Promise((resolve) => ( chrome.storage.local.get( - keys, - window.utils.getOrDie(resolve), + key, + window.utils.getOrDie((obj) => resolve(obj[key])), ) )); }, @@ -41,9 +41,13 @@ if (window.apis.platform.ifFirefox) { }, }, window.utils.chromified( async (err) => { if (err) { - throw err; + window.utils.lastError = err; + cb(); + return; } - await ffxStorage.set({ [`${prefix}-pacData`]: pac.data }); + window.pacData = pac.data; + window.ffxStorage = ffxStorage; + await ffxStorage.set({ [`${prefix}-pac-data`]: pac.data }); cb(); })); }; @@ -52,7 +56,9 @@ if (window.apis.platform.ifFirefox) { chrome.proxy.settings.get = function(details, cb) { originalGet(details, window.utils.chromified((err, originalDetails) => { if (err) { - throw err; + window.utils.lastError = err; + cb(originalDetails); + return; } const autoConfigUrl = window.utils.getProp(originalDetails, 'value.autoConfigUrl'); if (!autoConfigUrl) { @@ -60,7 +66,12 @@ if (window.apis.platform.ifFirefox) { } window.apis.httpLib.get(autoConfigUrl, async (err, pacData) => { if (err) { - pacData = await ffxStorage.get(`${prefix}-pacData`); + pacData = await ffxStorage.get(`${prefix}-pac-data`); + if (!pacData || !Object.keys(pacData).length) { + window.utils.lastError = err; + cb(originalDetails); + return; + } } cb(Object.assign( originalDetails, @@ -79,7 +90,7 @@ if (window.apis.platform.ifFirefox) { const originalClear = chrome.proxy.settings.clear.bind( chrome.proxy.settings ); chrome.proxy.settings.clear = async function(details, cb) { - await ffxStorage.remove(`${prefix}-pacData`); + await ffxStorage.remove(`${prefix}-pac-data`); originalClear(details, cb); }; } diff --git a/extensions/chromium/runet-censorship-bypass/src/extension-common/35-pac-kitchen-api.js b/extensions/chromium/runet-censorship-bypass/src/extension-common/35-pac-kitchen-api.js index 9c1bae5..bf50d34 100644 --- a/extensions/chromium/runet-censorship-bypass/src/extension-common/35-pac-kitchen-api.js +++ b/extensions/chromium/runet-censorship-bypass/src/extension-common/35-pac-kitchen-api.js @@ -626,16 +626,16 @@ ${ chrome.proxy.settings.set = function(details, cb) { const pac = window.utils.getProp(details, 'value.pacScript'); if (!(pac && pac.data)) { - return originalSet(details, cb); + return originalSet(details, window.utils.timeouted(cb)); } const pacMods = getCurrentConfigs(); pac.data = pacKitchen.cook( pac.data, pacMods ); originalSet({value: details.value}, window.utils.chromified((err) => { - if (err) { - throw err; + if (!err) { + kitchenState(ifIncontinence, null); } - kitchenState(ifIncontinence, null); + window.utils.lastError = err; cb && cb(); })); diff --git a/extensions/chromium/runet-censorship-bypass/src/extension-common/37-sync-pac-script-with-pac-provider-api.tmpl.js b/extensions/chromium/runet-censorship-bypass/src/extension-common/37-sync-pac-script-with-pac-provider-api.tmpl.js index 25ce730..09689db 100644 --- a/extensions/chromium/runet-censorship-bypass/src/extension-common/37-sync-pac-script-with-pac-provider-api.tmpl.js +++ b/extensions/chromium/runet-censorship-bypass/src/extension-common/37-sync-pac-script-with-pac-provider-api.tmpl.js @@ -380,12 +380,10 @@ } } - chrome.storage.local.clear( - () => chrome.storage.local.set( - onlySettable, - chromified(cb), - ) - ); + chrome.storage.local.set( + onlySettable, + chromified(cb), + ) },