I want to create a Chrome add-on that collects information about a new tab that is opened in Chrome. I would like to know why just using .onCreated.addListener callback function does not return the newly created tab, or if it does, why I can't access any of the properties(the way I do in my second attempt with chrome.tabs.query).
I guess I'm confused with regards to what is returned by:
chrome.tabs.onCreated.addListener's callback function
//In developer notes it's described as: 'returns details about the new tab'
//http://developer.chrome.com/extensions/tabs.html#event-onCreated
vs.
chrome.tabs.query callback function
//My understanding that it returns an array of Tab objects
//Assumed one Tab object is returned
chrome.tabs.onCreated.addListener(function(theTab){
for (var x = 0; x < theTab.length; x++){
alert(theTab[x].title);
}
});
//Active Tab object is returned
chrome.tabs.onCreated.addListener(function(){
chrome.tabs.query({active:true},function(theTab){
var url = theTab[0].url;
});
});
onCreated
's callback returns a Tab
object for the newly created tab, while query (as specified) should return all active tabs as an array. You shouldn't be trying to loop through a non-existent array.