1

See comments in code below:

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) { ... });

I'm I not allowed to do chrome.tabs.executeScript in a callback to specifically chrome.tabs.onUpdated.addListener ?

My use-case is that I need to run a startup script on every page refresh but only if my extension has been enabled.

manifest.json:

"permissions" : [
    "activeTab"
    "tabs",
    "http://*/*",
    "https://*/*"
],
Cotten
  • 8,787
  • 17
  • 61
  • 98
  • 2
    Did you reload your extension after setting the new permissions? And using onUpdated is not the best way to optionally inject content scripts. For better alternatives, see https://stackoverflow.com/questions/26667112/optionally-inject-content-script/26677279#26677279 – Rob W Jul 17 '15 at 13:45

1 Answers1

1

sorry, just a simple misstake of reloading the extension. When making changes to the .js files, it's enough just to hit cmd+r to reload it. It looks like when changing the manifest.json I needed to go to chrome://extentions and do a harder reload. Thanks to Rob W for the tip in the comment and link to better alternatives.

Cotten
  • 8,787
  • 17
  • 61
  • 98