issues executeScript permission

Viewed 5336

I'm trying to inject some code into the selected tab context from the background script but I've some problems with the permissions.

manifest.json

{
  "manifest_version": 2,
  "name": "prova",
  "version": "1.0",
  "permissions": [
    "activeTab"
  ],
  "background": {
    "scripts": ["background.js"],
    "persistent": false
  },
  "content_scripts": [
    {
      "matches": ["https://*"],
      "css": ["mystyles.css"],
      "js": ["myscript.js"]
    }
  ]
}

background.js

chrome.runtime.onMessage.addListener(
  function(request, sender, sendResponse) {
    chrome.tabs.executeScript(null,{code:"console.log('Not done!');"});
    sendResponse({});
  });

myscript.js

chrome.runtime.sendMessage({}, function(response) {
    console.log("Done!");
  });

That's the error appears in the background console:

Unchecked runtime.lastError while running tabs.executeScript: Cannot access contents of the page. Extension manifest must request permission to access the respective host.

I really appreciate every suggestion. Thanks a ton.

1 Answers
Related