使用浏览器扩展程序获取所有窗口中的所有选项卡的网址(Get the urls of all the

2019-09-01 00:31发布

这是可能的Chrome扩展获得使用Chrome扩展所有选项卡所有的网址吗?

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

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

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

"permissions": [
    "tabs"
]

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

Answer 1:

你可以这样做:

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


Answer 2:

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

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


文章来源: Get the urls of all the tabs in all windows using chrome extension