简体   繁体   English

chrome.tabs.query如何显示所有标签的信息?

[英]How can chrome.tabs.query show information of all tabs?

I am new to Chrome extension developing. 我是Chrome扩展开发的新手。 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. 据我所知, chrome.tabs.query仅在background.js中有效,而我试图使用下面的代码来检查返回的信息。 However, the result only returns to the background page console, and it only gives me the information of "chrome://extensions/" page. 但是,结果仅返回到后台页面控制台,并且仅提供“ chrome:// extensions /”页面的信息。

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! 提前致谢!

You just need to remove active key from query method, because it returns the current tab you are staying on. 您只需要从查询方法中删除active键,因为它会返回您当前停留的选项卡。 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 有关更多详细信息,您可以在此处查看query方法文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM