Search code examples
javascriptgoogle-chromegoogle-chrome-extensioncontent-script

Cannot run content script in chrome extension


I have written a code for writing google chrome extension but the problem is that i cannot execute the content script in the chrome console. Here is my following code

For Manifest file:-

    {
      "manifest_version": 2,

      "name": "My new extension",
      "description": "It does stuff",
      "version": "1"
      "content_scripts": [
    {
       "matches": ["<all_urls>"],
       "js": ["content.js"]
     }
   ]
 }

For my content script:-

     console.log("Hello world!");

When i deploy the extension, it is accepted properly. It should be printed at chrome console but when i refresh, nothing is printed. Can please anyone help me where I am wrong? Thanks in advance.


Solution

  • In order to inject content scripts you need to add at least the following permission in manifest:

    "permissions": ["activeTab"]
    

    Check the documentation