From ff5f77196243a2ad23ae6126648988ebc6cfcfe0 Mon Sep 17 00:00:00 2001 From: "YUKI \"Piro\" Hiroshi" Date: Mon, 13 Mar 2023 10:55:49 +0900 Subject: [PATCH] Simulate browser.tabs.selectOwnerOnClose more ceratainly --- webextensions/background/successor-tab.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/webextensions/background/successor-tab.js b/webextensions/background/successor-tab.js index 73cd190d8..27af6a6b9 100644 --- a/webextensions/background/successor-tab.js +++ b/webextensions/background/successor-tab.js @@ -90,13 +90,20 @@ function update(tabId) { }, 100); } async function updateInternal(tabId) { + // tabs.onActivated can be notified before the tab is completely tracked... + await Tab.waitUntilTracked(tabId); + const tab = Tab.get(tabId); + if (!tab) + return; + const promisedUpdate = mPromisedUpdatedSuccessorTabId.get(tabId); - if (promisedUpdate) - await promisedUpdate.promisedSuccessorTabId; + await Promise.all([ + tab.$TST.opened, + promisedUpdate && promisedUpdate.promisedSuccessorTabId, + ]); + const renewedTab = await browser.tabs.get(tabId).catch(ApiTabs.createErrorHandler(ApiTabs.handleMissingTabError)); - const tab = Tab.get(tabId); if (!renewedTab || - !tab || !TabsStore.ensureLivingTab(tab)) return; log('updateInternal: ', dumpTab(tab), { @@ -230,6 +237,7 @@ Tab.onCreating.addListener((tab, info = {}) => { configs.simulateSelectOwnerOnClose ); + log(`shouldControlSuccesor: `, shouldControlSuccesor); if (shouldControlSuccesor) { // don't use await here, to prevent that other onCreating handlers are treated async. tryClearOwnerSuccessor(info.activeTab).then(() => {