Get the urls of all the tabs in all windows using

2019-01-22 14:52发布

Is this possible for chrome extension to get all the URLs in all tabs using chrome extension ?

I have got the url of current Tab using this code

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

We need the following permissions in manifest.json file

"permissions": [
    "tabs"
]

My question is to find out the URLs in all tabs ?

2条回答
聊天终结者
2楼-- · 2019-01-22 15:22

With chrome.tabs.query method, you can also simply do,

 chrome.tabs.query({},function(tabs){     
    console.log("\n/////////////////////\n");
    tabs.forEach(function(tab){
      console.log(tab.url);
    });
 });
查看更多
霸刀☆藐视天下
3楼-- · 2019-01-22 15:26

You could do something like this:

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);
    });
  });
});
查看更多
登录 后发表回答