Skip to content

Commit ff5f771

Browse files
committed
Simulate browser.tabs.selectOwnerOnClose more ceratainly
1 parent a7790bb commit ff5f771

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

webextensions/background/successor-tab.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,20 @@ function update(tabId) {
9090
}, 100);
9191
}
9292
async function updateInternal(tabId) {
93+
// tabs.onActivated can be notified before the tab is completely tracked...
94+
await Tab.waitUntilTracked(tabId);
95+
const tab = Tab.get(tabId);
96+
if (!tab)
97+
return;
98+
9399
const promisedUpdate = mPromisedUpdatedSuccessorTabId.get(tabId);
94-
if (promisedUpdate)
95-
await promisedUpdate.promisedSuccessorTabId;
100+
await Promise.all([
101+
tab.$TST.opened,
102+
promisedUpdate && promisedUpdate.promisedSuccessorTabId,
103+
]);
104+
96105
const renewedTab = await browser.tabs.get(tabId).catch(ApiTabs.createErrorHandler(ApiTabs.handleMissingTabError));
97-
const tab = Tab.get(tabId);
98106
if (!renewedTab ||
99-
!tab ||
100107
!TabsStore.ensureLivingTab(tab))
101108
return;
102109
log('updateInternal: ', dumpTab(tab), {
@@ -230,6 +237,7 @@ Tab.onCreating.addListener((tab, info = {}) => {
230237
configs.simulateSelectOwnerOnClose
231238
);
232239

240+
log(`shouldControlSuccesor: `, shouldControlSuccesor);
233241
if (shouldControlSuccesor) {
234242
// don't use await here, to prevent that other onCreating handlers are treated async.
235243
tryClearOwnerSuccessor(info.activeTab).then(() => {

0 commit comments

Comments
 (0)