Reputation: 468
var windows = chrome.windows.getCurrent(
function(windows){
try{
// dont really know why this is null. it should be a list of tabs.
if(windows.tabs == null)
alert(windows.type + " " + windows.id);
}
catch(e){
alert(e);
}
});
I am using this code to get all the open tabs in the current window. But the window.tabs is always null even though there are tabs open in the current window. Is there something wrong with the concept of current window. Could anyone please explain what is it that i am doing wrong. Thanks.
Upvotes: 4
Views: 9273
Reputation: 13614
Looks like the windows
object that gets passed to your callback doesn't have a tabs
field. Try this code instead:
chrome.windows.getCurrent(function(win)
{
chrome.tabs.getAllInWindow(win.id, function(tabs)
{
// Should output an array of tab objects to your dev console.
console.debug(tabs);
});
});
Also ensure that you have the tabs
permission. I also ran this on a background page, so if you're not running it on a background page, you should make sure chrome.tabs
is available in your context.
Upvotes: 6