Q:

In a Chrome extension, why does a closed tab still exist when the callback passed to chrome.tabs.remove() is called?

If I pass a callback to chrome.tabs.remove(), I'd expect the callback to be called once the tab has been removed from the UI and and the current Chrome state.  In other words, if I run the following code in the background page of an extension that has the tabs permission, I'd expect it to generate an error, since trying to get a tab that doesn't exist sets runtime.lastError:
var tabs = [];
for (var i = 0; i < 3; i++) {
    chrome.tabs.create({ url: "chrome://newtab" }, tab => tabs.push(tab));
}

setTimeout(() => {
    var {id} = tabs[1];
    chrome.tabs.remove(id, () => chrome.tabs.get(id, 
        tab => console.log(id, tab)));
}, 2000);

But that's not what happens.  Three new blank tabs are opened and two seconds later the second one is closed, but the tab that was closed is still returned when calling chrome.tabs.get() in the callback that was passed to chrome.tabs.remove().  You'll see the full details of the removed tab logged to the console in the callback.
This seems like a bug in Chrome.  What possible use could there be for a callback in chrome.tabs.remove() to be called before the tab is removed?  Do I actually have to add an event listener for chrome.tabs.onRemoved before trying to remove a tab, just so I can be reliably notified when a tab is fully removed?

A:

Based on wOxxOm's comment above, this does seem like a bug or lazy implementation in Chrome, and the only workaround I can see is to add an event listener for onRemoved.
I ended up adding an event handler when my extension's popup window opened, but if you only wanted to be notified when your extension closes a tab, you could use something like this to get called back after the tab has been fully removed:
function closeTab(tabID, callback)
{
    function handleTabRemoved(tabID, removeInfo)
    {
        chrome.tabs.onRemoved.removeListener(handleTabRemoved);
        callback(tabID, removeInfo);
    }

    chrome.tabs.onRemoved.addListener(handleTabRemoved);
    chrome.tabs.remove(tabID);
}

closeTab(123, tabID => console.log(`Closed ${tabID}`);

(There's a potential edge case this doesn't handle where the user is closing a tab at exactly the same moment your extension is, but that's probably not worth worrying about.)

