From 243da0b0d12b79361e17e3595ca1ce232ab88a8e Mon Sep 17 00:00:00 2001 From: tophf Date: Sat, 26 Aug 2017 15:57:33 +0300 Subject: [PATCH] fix opening own pages from an incognito window popup in Chrome --- js/messaging.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/js/messaging.js b/js/messaging.js index 7d916bc9..a55191f1 100644 --- a/js/messaging.js +++ b/js/messaging.js @@ -178,12 +178,15 @@ function openURL({url, currentWindow = true}) { } } getActiveTab().then(tab => { - if (tab && tab.url === 'chrome://newtab/' - // prevent redirecting incognito NTP to a chrome URL as it crashes Chrome - && (!url.startsWith('chrome') || !tab.incognito)) { + const chromeInIncognito = tab && tab.incognito && url.startsWith('chrome'); + if (tab && tab.url === 'chrome://newtab/' && !chromeInIncognito) { + // update current NTP, except for chrome:// or chrome-extension:// in incognito chrome.tabs.update({url}, resolve); } else { - chrome.tabs.create(tab && !FIREFOX ? {url, openerTabId: tab.id} : {url}, resolve); + // create a new tab + const openerSupported = !FIREFOX && tab && !chromeInIncognito; + const options = openerSupported ? {url, openerTabId: tab.id} : {url}; + chrome.tabs.create(options, resolve); } }); });