Get the urls of all the tabs in all windows using

2019-01-22 15:02发布

问题:

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 ?

回答1:

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


回答2:

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