How to specify which content scripts which will ru

2019-02-27 17:29发布

问题:

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.

回答1:

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
    }
],