Google chrome extension chrome.tabs.executeScript在chrome.tabs.onUpdate回调中不工作

Google chrome extension chrome.tabs.executeScript在chrome.tabs.onUpdate回调中不工作,google-chrome-extension,Google Chrome Extension,请参见下面代码中的注释: chrome.browserAction.onClicked.addListener(function(tab) { // ################# This works without any problems chrome.tabs.executeScript(tabId, { code: '!!window.LoadedFlag' }, function (hasContentJs) { ... }); chrome.t

请参见下面代码中的注释:

chrome.browserAction.onClicked.addListener(function(tab) {

  // ################# This works without any problems
  chrome.tabs.executeScript(tabId, {
    code: '!!window.LoadedFlag'
    }, function (hasContentJs) { ... });


  chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {

    //  ################# This throws error:
    // Unchecked runtime.lastError while running tabs.executeScript:
    // Cannot access contents of url "http://localhost:3000/". Extension manifest must request permission to access this host.
    chrome.tabs.executeScript(tabId, {
      code: '!!window.LoadedFlag'
    }, function (hasContentJs) { ... });
我不允许在回调中执行
chrome.tabs.executeScript
,特别是
chrome.tabs.onUpdated.addListener

我的用例是,我需要在每次页面刷新时运行启动脚本,但前提是启用了扩展

manifest.json:

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

很抱歉,只是重新加载扩展的一个简单错误。在对.js文件进行更改时,只需点击
cmd+r
即可重新加载它。看起来在更改
manifest.json时,我需要转到
chrome://extentions
并进行更大的重新加载。感谢Rob W在评论中提供的提示和指向更好的备选方案的链接。

设置新权限后是否重新加载扩展?使用onUpdate并不是选择性地注入内容脚本的最佳方式。有关更好的替代方案,请参阅