Retrieving which tabs are open in Chrome?(检索 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 中打开了哪些标签页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:检索 Chrome 中打开了哪些标签页?
基础教程推荐
- fetch 是否支持原生多文件上传? 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
