admin管理员组

文章数量:1399974

I am new to Chrome extension developing. As far as I know, chrome.tabs.query only works in background.js, and I was trying to use the code below to check out the information returned. However, the result only returns to the background page console, and it only gives me the information of "chrome://extensions/" page.

chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
  console.log("tab ID:");
  console.log(tabs);
});

How can I get the information of all/any of the tabs that is opening in the current window?

Thanks in advance!

I am new to Chrome extension developing. As far as I know, chrome.tabs.query only works in background.js, and I was trying to use the code below to check out the information returned. However, the result only returns to the background page console, and it only gives me the information of "chrome://extensions/" page.

chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
  console.log("tab ID:");
  console.log(tabs);
});

How can I get the information of all/any of the tabs that is opening in the current window?

Thanks in advance!

Share Improve this question asked Jul 3, 2016 at 2:34 Adam LiuAdam Liu 1,34614 silver badges17 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

You just need to remove active key from query method, because it returns the current tab you are staying on. So all the tabs of the current window will be returned by the following:

chrome.tabs.query({currentWindow: true}, function(tabs) {
    tabs.forEach(function(tab) {
        console.log('Tab ID: ', tab.id);
    });
});

for more details you could take a look at query method docs here

本文标签: javascriptHow can chrometabsquery show information of all tabsStack Overflow