Fix: support kiwi browser

This commit is contained in:
eight04 2021-12-16 01:02:55 +08:00
parent 2d7668f254
commit 96959f9f21

View File

@ -99,25 +99,32 @@ bgReady.all.then(() => {
openInstallerPage(tabId, url, {}).catch(console.error); openInstallerPage(tabId, url, {}).catch(console.error);
// Silently suppress navigation. // Silently suppress navigation.
// Don't redirect to the install URL as it'll flash the text! // Don't redirect to the install URL as it'll flash the text!
return {redirectUrl: 'javascript:void 0'}; // eslint-disable-line no-script-url return {cancel: true};
} }
} }
function openInstallerPage(tabId, url, {code, inTab} = {}) { async function openInstallerPage(tabId, url, {code, inTab} = {}) {
const newUrl = `${URLS.installUsercss}?updateUrl=${encodeURIComponent(url)}`; const newUrl = `${URLS.installUsercss}?updateUrl=${encodeURIComponent(url)}`;
if (inTab) { if (inTab) {
browser.tabs.get(tabId).then(tab => const tab = browser.tabs.get(tabId);
openURL({ return openURL({
url: `${newUrl}&tabId=${tabId}`, url: `${newUrl}&tabId=${tabId}`,
active: tab.active, active: tab.active,
index: tab.index + 1, index: tab.index + 1,
openerTabId: tabId, openerTabId: tabId,
currentWindow: null, currentWindow: null,
})); });
} else { }
const timer = setTimeout(clearInstallCode, 10e3, url); const timer = setTimeout(clearInstallCode, 10e3, url);
installCodeCache[url] = {code, timer}; installCodeCache[url] = {code, timer};
chrome.tabs.update(tabId, {url: newUrl}); try {
await browser.tabs.update(tabId, {url: newUrl});
} catch (err) {
// FIXME: https://github.com/openstyles/stylus/issues/1367
if (/Tabs cannot be edited right now/i.test(err.message)) {
return browser.tabs.create({url: newUrl});
}
throw err;
} }
} }