Search code examples
javascriptiframegoogle-chrome-extensionmanifestframes

How to specify which content scripts which will run on all_frames and which won't?


When specifying parameters in the manifest file of a chrome extension there is an option all_frames. This allows the content scripts to be embedded in all frames of a page or not.

An example of what I want to achieve is have a.js running with all_frames=false and b.js with all_frames=true.


Solution

  • The content_scripts manifest property is an array, so you can define multiple content script specification objects:

    "content_scripts": [
        {
          "matches": ["http://www.google.com/*"],
          "css": ["mystyles.css"],
          "js": ["a.js"],
          "all_frames": false
        },
    
        {
          "matches": ["http://www.yahoo.com/*"],
          "js": ["b.js"],
          "all_frames": true
        }
    ],