Skip to content

Commit

Permalink
Simulate browser.tabs.selectOwnerOnClose more ceratainly
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Mar 13, 2023
1 parent a7790bb commit ff5f771
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions webextensions/background/successor-tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -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), {
Expand Down Expand Up @@ -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(() => {
Expand Down

0 comments on commit ff5f771

Please sign in to comment.