【问题标题】:Get the urls of all the tabs in all windows using chrome extension使用 chrome 扩展获取所有窗口中所有选项卡的 url
【发布时间】:2013-04-17 14:15:32
【问题描述】:

chrome 扩展是否可以使用 chrome 扩展获取所有选项卡中的所有 URL?

我已经使用此代码获得了当前选项卡的 url

chrome.tabs.getSelected(null, function(tab) {
    tabUrl = tab.url;
    alert(tabUrl);
});

我们需要 manifest.json 文件中的以下权限

"permissions": [
    "tabs"
]

我的问题是找出所有标签中的网址?

【问题讨论】:

  • 对于那些不想编写扩展程序来执行此操作但只想快速手动执行此操作的人:突出显示所有选项卡,将它们全部保存为新文件夹的书签,然后在书签管理器中,将所有书签复制到剪贴板。然后粘贴到记事本中。 howtogeek.com/723144/…

标签: google-chrome url google-chrome-extension tabs


【解决方案1】:

使用chrome.tabs.query方法,你也可以简单的做到,

 chrome.tabs.query({},function(tabs){     
    console.log("\n/////////////////////\n");
    tabs.forEach(function(tab){
      console.log(tab.url);
    });
 });

【讨论】:

  • 为了使 URL 可访问,必须在其 manifest.json 文件中包含 "permissions": [ "tabs"]
【解决方案2】:

你可以这样做:

chrome.windows.getAll({populate:true},function(windows){
  windows.forEach(function(window){
    window.tabs.forEach(function(tab){
      //collect all of the urls here, I will just log them instead
      console.log(tab.url);
    });
  });
});

【讨论】:

  • 我需要额外的 windows 权限吗?
  • @BeardFist 是 windows.forEach(...) 异步的吗?
  • 这仍然是推荐的获取方式还是 API 已弃用?
  • 你先生是个英雄
猜你喜欢
  • 1970-01-01
  • 2023-03-06
  • 2016-07-30
  • 1970-01-01
  • 2012-07-13
  • 2015-12-15
  • 1970-01-01
  • 1970-01-01
  • 2012-01-07
相关资源
最近更新 更多