Skip to content

Commit

Permalink
Tweaked tab removal to keep checking for the precise moment a tab is …
Browse files Browse the repository at this point in the history
…removed
  • Loading branch information
amoore17 committed Jan 17, 2020
1 parent cf7112a commit 5cb71ce
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions tab-numbering.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,26 @@ browser.tabs.onCreated.addListener(updateAll);
// Must listen for tabs being attached from other windows
browser.tabs.onAttached.addListener(updateAll);

// Must listen for tabs being moved
browser.tabs.onMoved.addListener(updateAll);

// Firefox seems to do this inconsistently, thus this setTimeout kludge
browser.tabs.onRemoved.addListener(() => {
updateAll();
setTimeout(updateAll, 100);
setTimeout(updateAll, 500);
setTimeout(updateAll, 1000);
// Must listen for tabs being removed
browser.tabs.onRemoved.addListener((tabId, removeInfo) => {
/* Check that the tab has been removed every 300ms.
Firefox fires onRemoved BEFORE it removes the tab */
const checkTabRemoval = () => {
browser.tabs.query({}, tabs => {
if (tabs.filter(tab => tab.id === tabId).length === 0)
updateAll();
else
setTimeout(checkTabRemoval, 300);
});
};

checkTabRemoval();
});

// Must listen for tab updates
browser.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
update(tab);
});
Expand Down

0 comments on commit 5cb71ce

Please sign in to comment.