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.
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.
Share Improve this question edited Dec 9, 2011 at 20:31 Jimmy Sawczuk 13.6k7 gold badges47 silver badges60 bronze badges asked Dec 9, 2011 at 20:15 intoTHEwildintoTHEwild 4688 silver badges24 bronze badges1 Answer
Reset to default 6Looks 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.