如何指定哪些内容脚本将在all_frames上运行,哪些不运行

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

本文关键字:运行 frames all 何指定 脚本      更新时间:2023-09-26

在chrome扩展的manifest文件中指定参数时,有一个选项all_frames。这使得内容脚本可以嵌入到页面的所有框架中,也可以不嵌入。

我想实现的一个例子是有a.js运行与all_frames=false和b.js与all_frames=true

content_scripts manifest属性是一个数组,所以你可以定义多个内容脚本规范对象:

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