首页 文章

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

提问于
浏览
12

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

我使用此代码获得了当前Tab的url

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

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

"permissions": [
    "tabs"
]

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

2 回答

  • 16

    你可以这样做:

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

    使用chrome.tabs.query方法,你也可以简单地做到,

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

相关问题