From 367ae56047303b9c2790c65db0b7b1ab51759734 Mon Sep 17 00:00:00 2001 From: tophf Date: Thu, 27 May 2021 14:34:19 +0300 Subject: [PATCH] reuse openURL so that the opener tab id is set --- background/background.js | 9 ++------- js/toolbox.js | 4 +++- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/background/background.js b/background/background.js index 18d97143..9ffaf1b2 100644 --- a/background/background.js +++ b/background/background.js @@ -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 }, /** diff --git a/js/toolbox.js b/js/toolbox.js index 0a1cfb34..55f5422b 100644 --- a/js/toolbox.js +++ b/js/toolbox.js @@ -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} 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,