diff --git a/src/duplicate-tab.js b/src/duplicate-tab.js index 4bbfd50..c42154b 100644 --- a/src/duplicate-tab.js +++ b/src/duplicate-tab.js @@ -136,7 +136,20 @@ export default class DuplicateTab { async #respondToPage(data, sender) { try { const { url, incognito, id } = await settings.session.getKeyValue(oldTabData) - if (data.selected === 'normal' || data.selected === 'normal-and-navigate-back') { + let goBack = async () => { + // We can only try to navigate back on the old tab because + // we need to have the activeTab permission as we're not + // requesting the generic scripting permission from the user + await browser.scripting.executeScript({ + target: { + tabId: id + }, + func: () => { + window.history.back() + } + }) + } + if (data.selected === 'normal' || (data.selected === 'normal-and-navigate-back' && !incognito)) { if (incognito === false) { await this.#duplicateSameTypeOfTab(id) } else { @@ -144,27 +157,20 @@ export default class DuplicateTab { await this.#getAndCloseAdvancedDuplicationPageAndClearData() } if (data.selected === 'normal-and-navigate-back') { - // We can only try to navigate back on the old tab because - // we need to have the activeTab permission as we're not - // requesting the generic scripting permission from the user - await browser.scripting.executeScript({ - target: { - tabId: id - }, - func: () => { - window.history.back() - } - }) + await goBack() } return true } - if (data.selected === 'private') { + if (data.selected === 'private' || (data.selected === 'normal-and-navigate-back' && incognito)) { if (incognito === true) { await this.#duplicateSameTypeOfTab(id) } else { await this.#createNewTabInWindow(url, true, true) await this.#getAndCloseAdvancedDuplicationPageAndClearData() } + if (data.selected === 'normal-and-navigate-back') { + await goBack() + } return true } if (data.selected === 'window' || data.selected === 'move-window') { diff --git a/src/page/main.js b/src/page/main.js index 7b31d52..e8ab9e9 100644 --- a/src/page/main.js +++ b/src/page/main.js @@ -84,6 +84,10 @@ buttons.forEach((b) => b.deleter = new IdempotentElementDeleter(b.element)) buttons.get('window').element.classList.remove('normal-style') buttons.get('move-window').element.classList.add('private-style') buttons.get('move-window').element.classList.remove('normal-style') + buttons.get('normal-and-navigate-back').element.classList.add('private-style') + buttons.get('normal-and-navigate-back').element.classList.remove('normal-style') + let navigateBackTabNav = document.querySelector('#normal-and-navigate-back-tab-name') + navigateBackTabNav.textContent = 'Private Browsing' } const { allowedIncognitoAccess } = response if (allowedIncognitoAccess === false) { diff --git a/src/page/page.html b/src/page/page.html index 08c17c1..37b0efc 100644 --- a/src/page/page.html +++ b/src/page/page.html @@ -30,15 +30,8 @@