检索 Chrome 中打开了哪些标签页? [英] Retrieving which tabs are open in Chrome?

查看:27
本文介绍了检索 Chrome 中打开了哪些标签页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在 Chrome 中检索所有打开的选项卡并将它们排序到一个数组中?因此,如果 Gmail 和 YouTube 已打开,则数组中将有两个条目,标题为gmail.com"和youtube.com".

Is there a way to retrieve all the tabs open and sort them in to an array in Chrome? So if Gmail and YouTube were open, there would be two entries in the array entitled "gmail.com" and "youtube.com".

推荐答案

是的,你可以这样做:

注意:这需要在清单文件中指定标签"权限.

Note: this requires permission "tabs" to be specified in your manifest file.

chrome.windows.getAll({populate:true}, getAllOpenWindows);

function getAllOpenWindows(winData) {

  var tabs = [];
  for (var i in winData) {
    if (winData[i].focused === true) {
        var winTabs = winData[i].tabs;
        var totTabs = winTabs.length;
        for (var j=0; j<totTabs;j++) {
          tabs.push(winTabs[j].url);
        }
    }
  }
  console.log(tabs);
}

在此示例中,我只是按照您在数组中的要求添加选项卡 url,但每个选项卡"对象都包含更多信息.Url 将是完整的 URL,您可以应用一些正则表达式从 URL 中提取域名.

In this example I am just adding tab url as you asked in an array but each "tab" object contains a lot more information. Url will be the full URL you can apply some regular expression to extract the domain names from the URL.

这篇关于检索 Chrome 中打开了哪些标签页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆