`browser.tabs.onRemoved` event listener still queries the removed tab

Hello there!

I am working on an add-on that focuses on open tabs and ran into this issue. It seems like all the other event listeners (onCreated, onAttached, onDetached, onMoved, and onUpdated) are all working except for onRemoved.

Here’s an short summary of the problem.
browser.tabs.onRemoved.addListener(handleRemoved);

async function handleRemoved(tabId: number, removeInfo: Tabs.OnRemovedRemoveInfoType): Promise<void> {
  const { windowId } = removeInfo;
  const allTabs = await browser.tabs.query({});
  console.log('[DEBUG] Tab length after remove', allTabs.length);
}

When I check the console.log, it is printing the length before the tab (that triggered the event) got removed.

I did a bit of searching and it seems like chrome.tabs.remove is the same way.

Hi!
I didn’t check described behavior and maybe it’s a bug, but onRemoved handler receives tabId. So if you want to get all tabs without removed, you can do something like this:

async function handleRemoved(tabId: number, removeInfo: Tabs.OnRemovedRemoveInfoType): Promise<void> {
  const allTabs = (await browser.tabs.query({})).filter(tab => tab.id !== tabId);
  console.log('[DEBUG] Tab length after remove', allTabs.length);
}