最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - chrome.windows.getCurrent is not returning the list of opened tabs - Stack Overflow

programmeradmin1浏览0评论
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 badges
Add a ment  | 

1 Answer 1

Reset to default 6

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.

发布评论

评论列表(0)

  1. 暂无评论