使用chrome扩展程序获取所有窗口中所有选项卡的URL

时间:2013-04-24 06:40:16

标签: google-chrome url google-chrome-extension tabs

Chrome扩展程序是否可以使用chrome扩展程序获取所有标签中的所有网址?

我已使用此代码获取当前Tab的网址

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

我们需要manifest.json文件中的以下权限

"permissions": [
    "tabs"
]

我的问题是找出所有标签中的网址?

2 个答案:

答案 0 :(得分:22)

你可以这样做:

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);
    });
  });
});

答案 1 :(得分:16)

使用chrome.tabs.query方法,您也可以这样做,

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