我正在构建一个附加组件,它有多个与之关联的 .js 文件,其中许多文件需要访问 require()
函数,但是当我在其中使用 require 函数时,我得到 require is not defined 的错误。使用 importScripts()
来包含 require.js
文件,但导入脚本也会产生错误。
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()
函数的文件。
最佳答案
看起来您正在使用附加 SDK。
您不能对所有 JS 文件使用特权代码,包括 require()。您只能使用 main.js 脚本中的特权代码。然后使用内容脚本/worker 在主脚本和其他脚本之间进行通信。
关于javascript - importScripts() 函数在 Firefox 插件代码中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31911802/