2013-04-24 115 views
10

这是可能的扩展铬使用扩展名获取所有选项卡中的所有URL?使用Chrome扩展获取所有窗口中所有选项卡的网址

我有当前选项卡的使用此代码

chrome.tabs.getSelected(null, function(tab) { 
    tabUrl = tab.url; 
    alert(tabUrl); 
}); 

的URL,我们需要在manifest.json档案以下权限

"permissions": [ 
    "tabs" 
] 

我的问题是要找出所有选项卡中的URL ?

回答

18

你可以做这样的事情:

chrome.windows.getAll({populate:true},function(windows){ 
    windows.forEach(function(window){ 
    window.tabs.forEach(function(tab){ 
     //collect all of the urls here, I will just log them instead 
     console.log(tab.url); 
    }); 
    }); 
}); 
+0

我是否需要额外的许可,这里的窗户? – sachinjain024 2013-04-24 07:55:22

+0

@blunderboy你需要'tabs'权限。 – BeardFist 2013-04-24 08:11:05

+0

@BeardFist是'windows.forEach(...)'异步? – MikeG 2016-12-04 05:30:30

12

随着chrome.tabs.query方法,你也可以简单地做,

chrome.tabs.query({},function(tabs){  
    console.log("\n/////////////////////\n"); 
    tabs.forEach(function(tab){ 
     console.log(tab.url); 
    }); 
}); 
相关问题