且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Google Chrome扩展程序中有多个后台脚本吗?

更新时间:2023-12-05 20:09:46

根据文档a>:

扩展系统将生成一个后台页面,其中包括scripts属性中列出的每个文件.

A background page will be generated by the extension system that includes each of the files listed in the scripts property.

是的,它应该可以工作.只需声明多个脚本:

So yes, it should work. Simply declare multiple scripts:

...
"background": {
  "scripts": [
    "background.js",
    "backgroundone.js",
    "backgroundtwo.js"
  ]
},
...

所有这些脚本都可以像加载到同一页面中一样工作.它们都将共享相同的上下文.

All of these scripts would work as if loaded into the same page; they will all share the same context.