0

When an extension is invoked or started, what is the first thing that is run? Is there some default .js file that is loaded first? Is there something comparable to main() in the C world? It's not clear from the tutorial or other doc what you have to write, what to call it, and where to put it so that it's the first thing that gets executed when an extension is launched/opened.

Thanks,

4

1 回答 1

1

正如@Rob-w 指出的那样,如果您创建了一个并在清单中正确定义了它,那么 background.js 将首先运行。

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

然后,如果您正在运行content-scripts,您可以使用指令在清单中指定执行这些脚本的点run_at。在大多数情况下,您会将脚本设置为在“document_end”运行,以便您可以与 DOM 交互。但您也可以将其设置为在“document_start”或“document_idle”运行(参见此处的用法)。

{
  "matches": ["*://www.whateverdomain.com/*"],
  "js": ["myscript.js"],
  "run_at": "document_end"
}
于 2013-05-23T16:17:53.790 回答