Fix: compatibility with kiwi (#1368)
This commit is contained in:
parent
f6e6a138db
commit
9d2854c272
|
@ -86,7 +86,7 @@ bgReady.all.then(() => {
|
||||||
const inTab = url.startsWith('file:') && !chrome.app;
|
const inTab = url.startsWith('file:') && !chrome.app;
|
||||||
const code = await (inTab ? loadFromFile : loadFromUrl)(tabId, url);
|
const code = await (inTab ? loadFromFile : loadFromUrl)(tabId, url);
|
||||||
if (!/^\s*</.test(code) && RX_META.test(code)) {
|
if (!/^\s*</.test(code) && RX_META.test(code)) {
|
||||||
openInstallerPage(tabId, url, {code, inTab});
|
await openInstallerPage(tabId, url, {code, inTab});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -99,25 +99,33 @@ bgReady.all.then(() => {
|
||||||
openInstallerPage(tabId, url, {});
|
openInstallerPage(tabId, url, {});
|
||||||
// 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 = await 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: remove this when kiwi supports tabs.update
|
||||||
|
// 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user