From 05d1b6f6be8a6f5ffbcb08e5ca5a8f389558a81b Mon Sep 17 00:00:00 2001 From: ilyaigpetrov Date: Mon, 12 Aug 2019 17:10:18 +0500 Subject: [PATCH 1/2] Bump 0.0.1.35 --- .../chromium/runet-censorship-bypass/src/templates-data.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/chromium/runet-censorship-bypass/src/templates-data.js b/extensions/chromium/runet-censorship-bypass/src/templates-data.js index 37c996e..65ecd98 100644 --- a/extensions/chromium/runet-censorship-bypass/src/templates-data.js +++ b/extensions/chromium/runet-censorship-bypass/src/templates-data.js @@ -10,7 +10,7 @@ const pacUrls = [ ]; const commonContext = { - version: '1.34', + version: '1.35', anticensorityPacUrls: [ ...pacUrls, ], From ad8aa3baed4fccd3007ab3ecf22f5d5fe46f7fc5 Mon Sep 17 00:00:00 2001 From: ilyaigpetrov Date: Fri, 16 Aug 2019 18:42:40 +0500 Subject: [PATCH 2/2] Hanlde error when tabId is -1 instead of throwing it --- .../src/extension-common/manifest.tmpl.json | 1 + .../pages/options/src/index.js | 1 + .../src/extension-full/80-error-menu.js | 56 ++++++++++++++++--- 3 files changed, 50 insertions(+), 8 deletions(-) diff --git a/extensions/chromium/runet-censorship-bypass/src/extension-common/manifest.tmpl.json b/extensions/chromium/runet-censorship-bypass/src/extension-common/manifest.tmpl.json index d81fc3f..7f19801 100644 --- a/extensions/chromium/runet-censorship-bypass/src/extension-common/manifest.tmpl.json +++ b/extensions/chromium/runet-censorship-bypass/src/extension-common/manifest.tmpl.json @@ -38,6 +38,7 @@ , "75-context-menus.js" ] }, + "browser_action": { "default_title": "Этот сайт благословлён | Версия ${version + versionSuffix}", "default_popup": "/pages/options/index.html" diff --git a/extensions/chromium/runet-censorship-bypass/src/extension-common/pages/options/src/index.js b/extensions/chromium/runet-censorship-bypass/src/extension-common/pages/options/src/index.js index 9268d7b..12027e3 100644 --- a/extensions/chromium/runet-censorship-bypass/src/extension-common/pages/options/src/index.js +++ b/extensions/chromium/runet-censorship-bypass/src/extension-common/pages/options/src/index.js @@ -40,6 +40,7 @@ chrome.runtime.getBackgroundPage( (bgWindow) => ([tab]) => resolve(tab), ) ); + winChrome.runtime.sendMessage({ currentTab, eventName: 'POPUP_OPENED' }); theState.flags.ifInsideOptionsPage = !currentTab || currentTab.url.startsWith('chrome://extensions/?options=') || currentTab.url.startsWith('about:addons'); theState.currentTab = currentTab; diff --git a/extensions/chromium/runet-censorship-bypass/src/extension-full/80-error-menu.js b/extensions/chromium/runet-censorship-bypass/src/extension-full/80-error-menu.js index 715a952..638b6de 100644 --- a/extensions/chromium/runet-censorship-bypass/src/extension-full/80-error-menu.js +++ b/extensions/chromium/runet-censorship-bypass/src/extension-full/80-error-menu.js @@ -2,6 +2,8 @@ { + const timeouted = window.utils.timeouted; + const proxySideErrors = [ 'net::ERR_TUNNEL_CONNECTION_FAILED', ]; @@ -44,17 +46,32 @@ throw new TypeError(msg); } - const tabId = details.tabId; + // Service workers have tabId = -1, get active tubId for them. + const tabId = details.tabId < 0 + ? await new Promise((resolve) => chrome.tabs.query( + { active: true }, + ([tab]) => resolve(tab.id)), + ) + : details.tabId; + + const [oldPopup, oldText, oldColor] = await new Promise((resolve) => + chrome.browserAction.getPopup({ tabId }, (oldPopup) => + chrome.browserAction.getBadgeText({ tabId }, (oldText) => + chrome.browserAction.getBadgeBackgroundColor({ tabId }, (oldColor) => resolve([ + oldPopup, + oldText, + oldColor, + ])), + ), + ) + ); + const popupPrefix = chrome.runtime.getURL(`/pages/options/index.html?status=🔥 Прокси-сервер отказался обслуживать запрос к `); - const oldPopup = await new Promise((resolve) => chrome.browserAction.getPopup({ tabId }, resolve)); if (decodeURIComponent(oldPopup).startsWith(popupPrefix)) { return true; } const popup = `${popupPrefix}${urlToA(details.url)}${fromPageHtml}. Это могло быть намеренно или по ошибке.${youMayReportHtml}#tab=exceptions`; - if (tabId < 0) { - throw new Error(`Вы выйграли экзотичную ошибку! Пожалуйста, сообщите нам о ней вместе с адресами ${toUrlHref} и ${fromPageHref}.`); - } chrome.browserAction.setPopup({ tabId, popup, @@ -68,6 +85,7 @@ tabId, text: '❗', }); + let limit = 5; let ifOnTurn = true; let ifError = false; @@ -87,10 +105,32 @@ }; flip(); const timer = setInterval(flip, 500); + + const restoringHandler = timeouted((eventDetails) => { + + if(eventDetails && tabId !== ((eventDetails.currentTab || eventDetails).id || eventDetails.tabId)) { + return; + } + clearInterval(timer); + + chrome.browserAction.setPopup({ tabId, popup: oldPopup}); + chrome.browserAction.setBadgeBackgroundColor({ tabId, color: oldColor}); + chrome.browserAction.setBadgeText({ tabId, text: oldText}); + + chrome.runtime.onMessage.removeListener(restoringHandler); + chrome.tabs.onRemoved.removeListener(restoringHandler); + chrome.tabs.onReplaced.removeListener(restoringHandler); + chrome.webNavigation.onBeforeNavigate.removeListener(restoringHandler); + }); + chrome.runtime.onMessage.addListener(restoringHandler); + chrome.tabs.onRemoved.addListener(restoringHandler); + chrome.tabs.onReplaced.addListener(restoringHandler); // When does it happen? + chrome.webNavigation.onBeforeNavigate.addListener(restoringHandler); + return true; }; - chrome.webNavigation.onErrorOccurred.addListener(async (details) => { + chrome.webNavigation.onErrorOccurred.addListener(timeouted(async (details) => { const tabId = details.tabId; if ( !(details.frameId === 0 && tabId >= 0) || @@ -118,10 +158,10 @@ text: '●●●', }); - }); + })); chrome.webRequest.onErrorOccurred.addListener( - isProxyErrorHandledAsync, + timeouted(isProxyErrorHandledAsync), {urls: ['']}, );