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?