From 96959f9f21eddc9050a5a1b28bdc016e2dced5a6 Mon Sep 17 00:00:00 2001 From: eight04 Date: Thu, 16 Dec 2021 01:02:55 +0800 Subject: [PATCH] Fix: support kiwi browser --- background/usercss-install-helper.js | 35 +++++++++++++++++----------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/background/usercss-install-helper.js b/background/usercss-install-helper.js index 42a9ea1f..7b30ca61 100644 --- a/background/usercss-install-helper.js +++ b/background/usercss-install-helper.js @@ -99,25 +99,32 @@ bgReady.all.then(() => { openInstallerPage(tabId, url, {}).catch(console.error); // Silently suppress navigation. // 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)}`; if (inTab) { - browser.tabs.get(tabId).then(tab => - openURL({ - url: `${newUrl}&tabId=${tabId}`, - active: tab.active, - index: tab.index + 1, - openerTabId: tabId, - currentWindow: null, - })); - } else { - const timer = setTimeout(clearInstallCode, 10e3, url); - installCodeCache[url] = {code, timer}; - chrome.tabs.update(tabId, {url: newUrl}); + const tab = browser.tabs.get(tabId); + return openURL({ + url: `${newUrl}&tabId=${tabId}`, + active: tab.active, + index: tab.index + 1, + openerTabId: tabId, + currentWindow: null, + }); + } + const timer = setTimeout(clearInstallCode, 10e3, url); + installCodeCache[url] = {code, timer}; + 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; } }