【问题标题】:Error: Components.utils undefined - Firefox Add-on错误:Components.utils 未定义 - Firefox 附加组件
【发布时间】:2015-11-12 04:26:00
【问题描述】:

我正在开发一个 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

【问题讨论】:

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


【解决方案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/

【讨论】:

    猜你喜欢
    • 2023-03-28
    • 1970-01-01
    • 1970-01-01
    • 2017-06-10
    • 1970-01-01
    • 1970-01-01
    • 2013-01-16
    相关资源
    最近更新 更多