如何重新加载Chrome扩展某些标签

enz*_*ett 3 javascript google-chrome-extension

我正在尝试从弹出窗口(特别是popup.js)重新加载用户可能在其选项卡之一中打开的页面。我正在查看此答案,但这仅适用于当前选项卡/sf/answers/1767224231/

它运行此外,当我得到这个错误:

popup.html:1 Unchecked runtime.lastError while running tabs.executeScript: Cannot access contents of url "thewebpageiamtryingtoaccess.com".
Extension manifest must request permission to access this host at Object.callback (chrome-extension://mjckbfpnokoplldjpijdfhffbbbfflah/popup.js:3:17)
Run Code Online (Sandbox Code Playgroud)

我已经添加了

"permissions": [
    "tabs"
  ],
Run Code Online (Sandbox Code Playgroud)

在我的表现,仍然没有运气。我将如何为用户打开的特定选项卡执行此操作。我希望这是在第一次加载扩展程序时重新加载网站,以便用户不必手动重新加载网页即可使内容脚本生效。谢谢!

Ser*_*nko 7

为了解决执行错误,您需要将清单文件中的权限更改为:

  "permissions": [
     "tabs",
     "http://*/",
     "https://*/"
  ]
Run Code Online (Sandbox Code Playgroud)

您可以通过网址查询标签的ID,如下所示:

chrome.tabs.query({url: "http://thewebpageiamtryingtoaccess.com/*"}, function(tab) {
   // reload tab with one of the methods from linked answer
   chrome.tabs.reload(tab[0].id) 
})
Run Code Online (Sandbox Code Playgroud)