The chrome.tabs.onRemoved event is chrome.tabs.onRemoved when the tab is deleted , and not when "it is going to get deleted." There is no way to get tab information after deleting it.
Information must be collected before deleting a tab. The chrome.tabs.onUpdated event is the most convenient event for this:
// Background script var tabToUrl = {}; chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) { // Note: this event is fired twice: // Once with `changeInfo.status` = "loading" and another time with "complete" tabToUrl[tabId] = tab.url; }); chrome.tabs.onRemoved.addListener(function(tabId, removeInfo) { do_stuff_with( tabToUrl[tabId] ); // Remove information for non-existent tab delete tabToUrl[tabId]; });
Obviously, you are not limited to saving only the URL in the tabToUrl object. Each type of tab contains primitive values (Boolean, integers, and strings), so storing the tab object will not lead to serious memory consumption.
However, the properties may be inaccurate, since onUpdated only starts when the page loads (re). If other properties are relevant, make sure you also attach event listeners to other chrome.tab events .
Rob w source share