[英]How do I make a content script load before another content script (that runs on the same event) in a Firefox extension?
Here's a portion of my manifest.json file:这是我 manifest.json 文件的一部分:
"content_scripts": [ {
"js": [ "common.js", "generation.js" ],
"matches": [ "*://www.site.com/*" ],
"run_at": "document_start"
},
{
"js": [ "page_init.js" ],
"matches": [ "*://www.site.com/*" ],
"run_at": "document_start"
},
Here, I want to run "common.js" before "page_init.js", as common.js contains much shared code and global variables and functions that the other content scripts need to function.在这里,我想在“page_init.js”之前运行“common.js”,因为 common.js 包含很多共享代码和全局变量和函数,其他内容脚本需要 function。 I have defined common.js before page_init.js in my manifest, and, in Chrome, doing this results in common.js running before all the other content scripts, which is what I need.
我在清单中的 page_init.js 之前定义了 common.js,并且在 Chrome 中,这样做会导致 common.js 在所有其他内容脚本之前运行,这正是我所需要的。 However, in Firefox, it doesn't seem to do this.
但是,在 Firefox 中,它似乎没有这样做。
When I run this extension in Firefox, however, page_init throws an error:但是,当我在 Firefox 中运行此扩展时,page_init 会引发错误:
ReferenceError: ReferenceError: href is not defined
"href" is a variable that's defined in common.js. “href”是一个在 common.js 中定义的变量。
Do I need to make page_init.js run at document_end in order for common.js to fully run, or is there another way?我是否需要让 page_init.js 在 document_end 运行才能使 common.js 完全运行,还是有其他方法? I need them to both run at document_start.
我需要它们都在 document_start 上运行。
From firefox documentation :来自firefox 文档:
js
js
An array of paths, relative to manifest.json, referencing JavaScript files that will be injected into matching pages.
相对于 manifest.json 的路径数组,引用将注入匹配页面的 JavaScript 文件。
Files are injected in the order given .
文件按给定的顺序注入。 This means that, for example, if you include jQuery here followed by another content script, like this...
这意味着,例如,如果您在此处包含 jQuery 后跟另一个内容脚本,如下所示...
It's probably a firefox bug, you may want to report it.这可能是一个 firefox 错误,您可能需要报告它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.