Reputation: 1654
Should be straight-forward, right? We have the following listener at our disposal.
chrome.tabs.onRemoved.addListener(function (tabId, removeinfo))
tabId won't be valid anymore though since that tab has been removed. That leaves us with the removeinfo object, but the chrome documentation does not indicate what properties it contains. I am a javascript newbie so I have no idea if there is a way to get the properties through some kind of reflection process.
Any ideas? I've tried around 50 google searches so far.
Upvotes: 4
Views: 2063
Reputation: 914
In general, if you want to poke through JS object contents, you can just spit it out to the console with console.log(thing)
or console.debug(thing)
. The console opens with Ctrl+Shift+J, or Opt+Cmd+J on Mac.
Having done that, however, I can tell you that the removeInfo
object doesn't have the info you need. It's kind of a pain, but you'll have to add listeners to onCreated and onUpdated as well in order to keep track of the tabID-to-URL mapping using some global object as a hashtable, and then use the tabID on that object to retrieve the URL. Note that these events require the tabs
permission. (More info here: http://code.google.com/chrome/extensions/tabs.html)
If you can describe your use case and make a case for changing the API, I'd suggest opening a ticket at http://new.crbug.com.
Upvotes: 1
Reputation: 47833
removeInfo
in onRemoved is a object that contains a single boolean value. It should look like this { isWindowClosing: false }
.
You will have to maintain an array of URLs as tabs with the onUpdated event. If the URL is present save it into an array and when an onRemoved
event triggers you will have the URL saved.
var urls = [];
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
if (changeInfo.url) {
urls[tabId] = changeInfo.url;
}
});
When you want the URL of a tab that just closed you can use var url = urls[tabId];
Upvotes: 7