简体   繁体   English

Google Chrome 扩展程序:如何获取打开标签的所有网址?

[英]Google Chrome Extension: How to get all urls of opening tab?

I'm using chome.tabs.query to get all detail from all tabs are opening in Chrome.我正在使用chome.tabs.query来获取在 Chrome 中打开的所有选项卡的所有详细信息。

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

However, in the results I received, I could not find the URL of the tab page.但是,在我收到的结果中,我找不到标签页的 URL。 The information is the same as信息是一样的

{
  active: false
  audible: false
  autoDiscardable: true
  discarded: false
  groupId: -1
  height: 748
  highlighted: false
  id: 134
  incognito: false
  index: 1
  mutedInfo: {muted: false}
  pinned: false
  selected: false
  status: "complete"
  width: 1440
  windowId: 4
}

Is there a way that allows me to get all the information of the open tabs according to its URL?有没有办法让我根据它的 URL 获取打开标签的所有信息?

My Chrome version: 89.04我的 Chrome 版本:89.04

Have you add "tabs" permission in manifest.json?您是否在 manifest.json 中添加了“选项卡”权限?

From https://developer.chrome.com/docs/extensions/reference/tabs/#type-Tab来自https://developer.chrome.com/docs/extensions/reference/tabs/#type-Tab

URL property is only present if the extension's manifest includes the "tabs" permission and may be an empty string if the tab has not yet committed. URL 属性仅在扩展的清单包含“选项卡”权限时才存在,并且如果选项卡尚未提交,则可能是空字符串。

You can use several methods of tabs API without "tabs" permission but if you want to retreive this kind of information from a query you have to include tabs permission in manifest.您可以在没有“选项卡”权限的情况下使用选项卡 API 的几种方法,但是如果您想从查询中检索此类信息,则必须在清单中包含选项卡权限。

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

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