From fa1496ecb8054f454f3aaecb16d6f2c0eb46881e Mon Sep 17 00:00:00 2001 From: tophf Date: Tue, 22 Sep 2020 13:54:48 +0300 Subject: [PATCH] use tab.pendingUrl (#1040) --- background/background.js | 2 +- background/content-scripts.js | 4 ++-- background/navigator-util.js | 5 +++-- edit/regexp-tester.js | 3 +-- js/messaging.js | 7 +++---- js/msg.js | 7 ++++--- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/background/background.js b/background/background.js index 77034880..6851006e 100644 --- a/background/background.js +++ b/background/background.js @@ -328,7 +328,7 @@ function openManage({options = false, search} = {}) { if (tab) { return Promise.all([ activateTab(tab), - tab.url !== url && msg.sendTab(tab.id, {method: 'pushState', url}) + (tab.pendingUrl || tab.url) !== url && msg.sendTab(tab.id, {method: 'pushState', url}) .catch(console.error) ]); } diff --git a/background/content-scripts.js b/background/content-scripts.js index dfd744f2..d3c93b40 100644 --- a/background/content-scripts.js +++ b/background/content-scripts.js @@ -58,13 +58,13 @@ const contentScripts = (() => { return browser.tabs.query({}).then(tabs => { for (const tab of tabs) { // skip unloaded/discarded/chrome tabs - if (!tab.width || tab.discarded || !URLS.supported(tab.url)) continue; + if (!tab.width || tab.discarded || !URLS.supported(tab.pendingUrl || tab.url)) continue; // our content scripts may still be pending injection at browser start so it's too early to ping them if (tab.status === 'loading') { trackBusyTab(tab.id, true); } else { injectToTab({ - url: tab.url, + url: tab.pendingUrl || tab.url, tabId: tab.id }); } diff --git a/background/navigator-util.js b/background/navigator-util.js index 67fdc1e7..c1b702c6 100644 --- a/background/navigator-util.js +++ b/background/navigator-util.js @@ -49,8 +49,9 @@ const navigatorUtil = (() => { } return browser.tabs.get(data.tabId) .then(tab => { - if (tab.url === 'chrome://newtab/') { - data.url = tab.url; + const url = tab.pendingUrl || tab.url; + if (url === 'chrome://newtab/') { + data.url = url; } }); } diff --git a/edit/regexp-tester.js b/edit/regexp-tester.js index 8f001102..5b7bf13e 100644 --- a/edit/regexp-tester.js +++ b/edit/regexp-tester.js @@ -67,8 +67,7 @@ const regExpTester = (() => { }); const getMatchInfo = m => m && {text: m[0], pos: m.index}; browser.tabs.query({}).then(tabs => { - const supported = tabs.map(tab => tab.url) - .filter(url => URLS.supported(url)); + const supported = tabs.map(tab => tab.pendingUrl || tab.url).filter(URLS.supported); const unique = [...new Set(supported).values()]; for (const rxData of regexps) { const {rx, urls} = rxData; diff --git a/js/messaging.js b/js/messaging.js index 642b20dc..e7f0e9da 100644 --- a/js/messaging.js +++ b/js/messaging.js @@ -132,7 +132,7 @@ function findExistingTab({url, currentWindow, ignoreHash = true, ignoreSearch = .then(tabs => tabs.find(matchTab)); function matchTab(tab) { - const tabUrl = new URL(tab.url); + const tabUrl = new URL(tab.pendingUrl || tab.url); return tabUrl.protocol === url.protocol && tabUrl.username === url.username && tabUrl.password === url.password && @@ -175,7 +175,7 @@ function openURL({ index, openerTabId, // when hash is different we can only set `url` if it has # otherwise the tab would reload - url: url !== tab.url && url.includes('#') ? url : undefined, + url: url !== (tab.pendingUrl || tab.url) && url.includes('#') ? url : undefined, }); } if (newWindow && browser.windows) { @@ -200,10 +200,9 @@ function openURL({ // except when new URL is chrome:// or chrome-extension:// and the empty tab is // in incognito function isTabReplaceable(tab, newUrl) { - if (!tab || !URLS.emptyTab.includes(tab.url)) { + if (!tab || !URLS.emptyTab.includes(tab.pendingUrl || tab.url)) { return false; } - // FIXME: but why? if (tab.incognito && newUrl.startsWith('chrome')) { return false; } diff --git a/js/msg.js b/js/msg.js index d52438e4..26dba45d 100644 --- a/js/msg.js +++ b/js/msg.js @@ -106,12 +106,13 @@ self.msg = self.INJECTED === 1 ? self.msg : (() => { .then(tabs => { const requests = []; for (const tab of tabs) { - const isExtension = tab.url.startsWith(EXTENSION_URL); + const tabUrl = tab.pendingUrl || tab.url; + const isExtension = tabUrl.startsWith(EXTENSION_URL); if ( tab.discarded || // FIXME: use `URLS.supported`? - !/^(http|ftp|file)/.test(tab.url) && - !tab.url.startsWith('chrome://newtab/') && + !/^(http|ftp|file)/.test(tabUrl) && + !tabUrl.startsWith('chrome://newtab/') && !isExtension || isExtension && ignoreExtension || filter && !filter(tab)