mirror of
https://github.com/anticensority/runet-censorship-bypass.git
synced 2024-11-24 02:13:43 +03:00
Hanlde error when tabId is -1 instead of throwing it
This commit is contained in:
parent
05d1b6f6be
commit
ad8aa3baed
|
@ -38,6 +38,7 @@
|
||||||
, "75-context-menus.js"
|
, "75-context-menus.js"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
"browser_action": {
|
"browser_action": {
|
||||||
"default_title": "Этот сайт благословлён | Версия ${version + versionSuffix}",
|
"default_title": "Этот сайт благословлён | Версия ${version + versionSuffix}",
|
||||||
"default_popup": "/pages/options/index.html"
|
"default_popup": "/pages/options/index.html"
|
||||||
|
|
|
@ -40,6 +40,7 @@ chrome.runtime.getBackgroundPage( (bgWindow) =>
|
||||||
([tab]) => resolve(tab),
|
([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.flags.ifInsideOptionsPage = !currentTab || currentTab.url.startsWith('chrome://extensions/?options=') || currentTab.url.startsWith('about:addons');
|
||||||
theState.currentTab = currentTab;
|
theState.currentTab = currentTab;
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
||||||
|
const timeouted = window.utils.timeouted;
|
||||||
|
|
||||||
const proxySideErrors = [
|
const proxySideErrors = [
|
||||||
'net::ERR_TUNNEL_CONNECTION_FAILED',
|
'net::ERR_TUNNEL_CONNECTION_FAILED',
|
||||||
];
|
];
|
||||||
|
@ -44,17 +46,32 @@
|
||||||
throw new TypeError(msg);
|
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=<span style="color: red">🔥 Прокси-сервер отказался обслуживать запрос к `);
|
const popupPrefix = chrome.runtime.getURL(`/pages/options/index.html?status=<span style="color: red">🔥 Прокси-сервер отказался обслуживать запрос к `);
|
||||||
const oldPopup = await new Promise((resolve) => chrome.browserAction.getPopup({ tabId }, resolve));
|
|
||||||
if (decodeURIComponent(oldPopup).startsWith(popupPrefix)) {
|
if (decodeURIComponent(oldPopup).startsWith(popupPrefix)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
const popup = `${popupPrefix}${urlToA(details.url)}${fromPageHtml}</span>. Это могло быть намеренно или по ошибке.${youMayReportHtml}#tab=exceptions`;
|
const popup = `${popupPrefix}${urlToA(details.url)}${fromPageHtml}</span>. Это могло быть намеренно или по ошибке.${youMayReportHtml}#tab=exceptions`;
|
||||||
|
|
||||||
if (tabId < 0) {
|
|
||||||
throw new Error(`Вы выйграли экзотичную ошибку! Пожалуйста, сообщите нам о ней вместе с адресами ${toUrlHref} и ${fromPageHref}.`);
|
|
||||||
}
|
|
||||||
chrome.browserAction.setPopup({
|
chrome.browserAction.setPopup({
|
||||||
tabId,
|
tabId,
|
||||||
popup,
|
popup,
|
||||||
|
@ -68,6 +85,7 @@
|
||||||
tabId,
|
tabId,
|
||||||
text: '❗',
|
text: '❗',
|
||||||
});
|
});
|
||||||
|
|
||||||
let limit = 5;
|
let limit = 5;
|
||||||
let ifOnTurn = true;
|
let ifOnTurn = true;
|
||||||
let ifError = false;
|
let ifError = false;
|
||||||
|
@ -87,10 +105,32 @@
|
||||||
};
|
};
|
||||||
flip();
|
flip();
|
||||||
const timer = setInterval(flip, 500);
|
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;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
chrome.webNavigation.onErrorOccurred.addListener(async (details) => {
|
chrome.webNavigation.onErrorOccurred.addListener(timeouted(async (details) => {
|
||||||
|
|
||||||
const tabId = details.tabId;
|
const tabId = details.tabId;
|
||||||
if ( !(details.frameId === 0 && tabId >= 0) ||
|
if ( !(details.frameId === 0 && tabId >= 0) ||
|
||||||
|
@ -118,10 +158,10 @@
|
||||||
text: '●●●',
|
text: '●●●',
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
}));
|
||||||
|
|
||||||
chrome.webRequest.onErrorOccurred.addListener(
|
chrome.webRequest.onErrorOccurred.addListener(
|
||||||
isProxyErrorHandledAsync,
|
timeouted(isProxyErrorHandledAsync),
|
||||||
{urls: ['<all_urls>']},
|
{urls: ['<all_urls>']},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user