diff --git a/src/js/background/backgroundLogic.js b/src/js/background/backgroundLogic.js index 96a1b26..5d71fec 100644 --- a/src/js/background/backgroundLogic.js +++ b/src/js/background/backgroundLogic.js @@ -112,11 +112,12 @@ const backgroundLogic = { return list.concat(containerState.hiddenTabs); }, - async unhideContainer(cookieStoreId) { + async unhideContainer(cookieStoreId, alreadyShowingUrl) { if (!this.unhideQueue.includes(cookieStoreId)) { this.unhideQueue.push(cookieStoreId); await this.showTabs({ - cookieStoreId + cookieStoreId, + alreadyShowingUrl }); this.unhideQueue.splice(this.unhideQueue.indexOf(cookieStoreId), 1); } @@ -308,13 +309,16 @@ const backgroundLogic = { const containerState = await identityState.storageArea.get(options.cookieStoreId); for (let object of containerState.hiddenTabs) { // eslint-disable-line prefer-const - promises.push(this.openNewTab({ - userContextId: userContextId, - url: object.url, - nofocus: options.nofocus || false, - noload: true, - pinned: object.pinned, - })); + // do not show already opened url + if (object.url !== options.alreadyShowingUrl) { + promises.push(this.openNewTab({ + userContextId: userContextId, + url: object.url, + nofocus: options.nofocus || false, + noload: true, + pinned: object.pinned, + })); + } } containerState.hiddenTabs = []; diff --git a/src/js/background/messageHandler.js b/src/js/background/messageHandler.js index 132f0a7..dcd8af6 100644 --- a/src/js/background/messageHandler.js +++ b/src/js/background/messageHandler.js @@ -153,9 +153,26 @@ const messageHandler = { !tab.url.startsWith("moz-extension")) { // increment the counter of container tabs opened this.incrementCountOfContainerTabsOpened(); - } - backgroundLogic.unhideContainer(tab.cookieStoreId); + this.tabUpdateHandler = (tabId, changeInfo) => { + if (tabId === tab.id && changeInfo.status === "complete") { + // get current tab's url to not open the same one from hidden tabs + browser.tabs.get(tabId).then(loadedTab => { + backgroundLogic.unhideContainer(tab.cookieStoreId, loadedTab.url); + }).catch((e) => { + throw e; + }); + + browser.tabs.onUpdated.removeListener(this.tabUpdateHandler); + } + }; + + // if it's a container tab wait for it to complete and + // unhide other tabs from this container + if (tab.cookieStoreId.startsWith("firefox-container")) { + browser.tabs.onUpdated.addListener(this.tabUpdateHandler); + } + } } setTimeout(() => { this.lastCreatedTab = null;