【问题标题】:How to reload certain tab in chrome extension如何在 chrome 扩展中重新加载某些选项卡
【发布时间】:2018-01-12 05:29:35
【问题描述】:

我正在尝试重新加载用户可能已从弹出窗口(特别是 popup.js)的其中一个选项卡中打开的页面。我正在查看这个答案,但它仅适用于当前标签 https://stackoverflow.com/a/25246060/8786209

当它运行时我得到这个错误:

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)

我已经添加了

"permissions": [
    "tabs"
  ],

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

【问题讨论】:

    标签: javascript google-chrome-extension


    【解决方案1】:

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

      "permissions": [
         "tabs",
         "http://*/",
         "https://*/"
      ]
    

    你可以像这样通过url查询标签的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) 
    })
    

    【讨论】:

      猜你喜欢
      • 2012-03-14
      • 1970-01-01
      • 2013-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-05
      • 2012-09-04
      相关资源
      最近更新 更多