importScripts()函数在Firefox插件代码中不起作用 [英] importScripts() function not working in Firefox addon code
问题描述
我正在构建一个附加组件,其中包含多个与之关联的.js文件,其中许多文件需要访问 require()
函数,但是当我使用它时其中的require函数我得到了未定义的错误。使用 importScripts()
包含 require.js
文件,但导入scrips也会产生错误。
I am building an add-on that has multiple .js files that are associated with it many of which need the access to the require()
function but when i use the require function in them i get the error that require is not defined.used importScripts()
to include the require.js
file but the import scrips also generates error.
importScripts('resource://gre/modules/workers/require.js');
也使用
self.importScripts('resource://gre/modules/workers/require.js');
产生的错误是
JPM undefined Message: ReferenceError: importScripts is not defined
和
JPM undefined Message: ReferenceError: importScripts is not defined
需要帮助才能包含多个可以访问 require()
或 importScripts的文件()
function。
Need help to include multiple files that can have the access to the require()
or importScripts()
function.
推荐答案
看起来你正在使用附加组件SDK。
Looks like you're using the add-on SDK.
您不能对所有JS文件使用特权代码,包括require()。您只能使用main.js脚本中的特权代码。然后使用内容脚本/ worker在主脚本和其他脚本之间进行通信。
You can't use privileged code with all JS files, that includes require(). You can only use privileged code from your main.js script. Then use a content script/worker to communicate between the main script and the other script.
这篇关于importScripts()函数在Firefox插件代码中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!