reuse openURL so that the opener tab id is set

This commit is contained in:
tophf 2021-05-27 14:34:19 +03:00
parent 18265b94c6
commit 367ae56047
2 changed files with 5 additions and 8 deletions

View File

@ -12,8 +12,6 @@
activateTab
download
findExistingTab
getActiveTab
isTabReplaceable
openURL
*/ // toolbox.js
'use strict';
@ -74,7 +72,7 @@ addAPI(/** @namespace API */ {
if (options) {
url += '#stylus-options';
}
let tab = await findExistingTab({
const tab = await findExistingTab({
url,
currentWindow: null,
ignoreHash: true,
@ -87,10 +85,7 @@ addAPI(/** @namespace API */ {
}
return tab;
}
tab = await getActiveTab();
return isTabReplaceable(tab, url)
? activateTab(tab, {url})
: browser.tabs.create({url}).then(activateTab); // activateTab unminimizes the window
return openURL({url, ignoreExisting: true}).then(activateTab); // activateTab unminimizes the window
},
/**

View File

@ -179,6 +179,7 @@ async function findExistingTab({url, currentWindow, ignoreHash = true, ignoreSea
* @param {Boolean} [_.active=true] `true` to activate the tab
* @param {Boolean|null} [_.currentWindow=true] `null` to check all windows
* @param {chrome.windows.CreateData} [_.newWindow] creates a new window with these params if specified
* @param {boolean} [_.ignoreExisting] specify to skip findExistingTab
* @returns {Promise<chrome.tabs.Tab>} Promise -> opened/activated tab
*/
async function openURL({
@ -188,11 +189,12 @@ async function openURL({
active = true,
currentWindow = true,
newWindow,
ignoreExisting,
}) {
if (!url.includes('://')) {
url = chrome.runtime.getURL(url);
}
let tab = await findExistingTab({url, currentWindow});
let tab = !ignoreExisting && await findExistingTab({url, currentWindow});
if (tab) {
return activateTab(tab, {
index,