错误:Components.utils undefined - Firefox附加组件

时间:2015-11-11 18:40:44

标签: javascript firefox import firefox-addon firefox-addon-sdk

我正在开发一个Firefox附加组件(使用附加SDK),我需要使用cookie。为此,我应该导入"Services.jsm"模块。

我已按照MDN的说明进行操作,建议使用

Components.utils.import("resource://gre/modules/Services.jsm");

我也尝试过:

Components.utils["import"]("resource://gre/modules/Services.jsm");

使用时我得到:

- _errorType = TypeError
- message = Components.utils is undefined

有人知道如何解决这个问题吗?

参考文献: Components.utils.import

1 个答案:

答案 0 :(得分:1)

使用Addon-on SDK时,必须以这种方式导入:

const { Cu } = require("chrome");
let Services = Cu.import("resource://gre/modules/Services.jsm");

有关详细信息,请参阅https://blog.mozilla.org/addons/2012/02/16/using-jsm-modules-in-the-sdk/