diff --git a/webextension/js/background/backgroundLogic.js b/webextension/js/background/backgroundLogic.js index c044eb5..36bcb47 100644 --- a/webextension/js/background/backgroundLogic.js +++ b/webextension/js/background/backgroundLogic.js @@ -63,8 +63,7 @@ const backgroundLogic = { url = undefined; } - // We can't open these we just have to throw them away - if (new URL(url).protocol === "about:") { + if (!this.isPermissibleURL(url)) { return; } @@ -76,6 +75,17 @@ const backgroundLogic = { }); }, + isPermissibleURL(url) { + const protocol = new URL(url).protocol; + // We can't open these we just have to throw them away + if (protocol === "about:" + || protocol === "chrome:" + || protocol === "moz-extension:") { + return false; + } + return true; + }, + checkArgs(requiredArguments, options, methodName) { requiredArguments.forEach((argument) => { if (!(argument in options)) { @@ -118,20 +128,37 @@ const backgroundLogic = { containerState.hiddenTabs.length === 0) { return; } - const newWindowObj = await browser.windows.create({ - tabId: list.shift().id - }); - browser.tabs.move(list.map((tab) => tab.id), { - windowId: newWindowObj.id, - index: -1 - }); + let newWindowObj; + let hiddenDefaultTabToClose; + if (list.length) { + newWindowObj = await browser.windows.create({ + tabId: list.shift().id + }); + browser.tabs.move(list.map((tab) => tab.id), { + windowId: newWindowObj.id, + index: -1 + }); + } else { + //As we get a blank tab here we will need to await the tabs creation + newWindowObj = await browser.windows.create({ + }); + hiddenDefaultTabToClose = true; + } + + const showHiddenPromises = []; // Let's show the hidden tabs. for (let object of containerState.hiddenTabs) { // eslint-disable-line prefer-const - browser.tabs.create(object.url || DEFAULT_TAB, { + showHiddenPromises.push(browser.tabs.create({ + url: object.url || DEFAULT_TAB, windowId: newWindowObj.id, cookieStoreId - }); + })); + } + + if (hiddenDefaultTabToClose) { + // Lets wait for hidden tabs to show before closing the others + await showHiddenPromises; } containerState.hiddenTabs = []; @@ -139,9 +166,9 @@ const backgroundLogic = { // Let's close all the normal tab in the new window. In theory it // should be only the first tab, but maybe there are addons doing // crazy stuff. - const tabs = browser.tabs.query({windowId: newWindowObj.id}); + const tabs = await browser.tabs.query({windowId: newWindowObj.id}); for (let tab of tabs) { // eslint-disable-line prefer-const - if (tabs.cookieStoreId !== cookieStoreId) { + if (tab.cookieStoreId !== cookieStoreId) { browser.tabs.remove(tab.id); } } diff --git a/webextension/js/background/identityState.js b/webextension/js/background/identityState.js index a563d90..fbb0020 100644 --- a/webextension/js/background/identityState.js +++ b/webextension/js/background/identityState.js @@ -41,6 +41,9 @@ const identityState = { const tabsByContainer = await browser.tabs.query({cookieStoreId, windowId}); tabsByContainer.forEach((tab) => { const tabObject = this._createTabObject(tab); + if (!backgroundLogic.isPermissibleURL(tab.url)) { + return; + } // This tab is going to be closed. Let's mark this tabObject as // non-active. tabObject.active = false; diff --git a/webextension/js/background/messageHandler.js b/webextension/js/background/messageHandler.js index 2283e5f..b71ad02 100644 --- a/webextension/js/background/messageHandler.js +++ b/webextension/js/background/messageHandler.js @@ -39,7 +39,7 @@ const messageHandler = { backgroundLogic.sortTabs(); break; case "showTabs": - backgroundLogic.showTabs({cookieStoreId: m.cookieStoreId}); + this.unhideContainer(m.cookieStoreId); break; case "hideTabs": backgroundLogic.hideTabs({