【问题标题】:Thunderbird extension console loggingThunderbird 扩展控制台日志记录
【发布时间】:2013-05-22 08:23:27
【问题描述】:

我的引导式 Thunderbird 附加组件 main.js 文件中有以下代码:

exports.main = function() {
    console.log("abc");
};

当我在 Add-on Builder 中的 FireFox 中运行此代码时,我在 FireFox 错误控制台中显示此消息:

info: vladp: abc

但是,当我在 Thunderbird 中运行我的扩展程序时,什么都没有显示。我已经按照此处所述设置了开发环境:https://developer.mozilla.org/en-US/docs/Setting_up_extension_development_environment

如何使它在 Thunderbird 错误控制台中工作?或者除了“dump()”还有其他方法可以记录一些调试信息吗?

更新 1

根据 speedball2001 的建议,我已将代码更改为:

exports.main = function() { 
    var Application = Components.classes["@mozilla.org/steel/application;1"].getService(Components.interfaces.steelIApplication);
    Application.console.log('Bam!');
};

但是,当我运行 Thunderbird 时,我在错误控制台中收到以下错误:

Timestamp: 2013.05.22. 16:39:07
Error: myfirstext: An exception occurred.
ReferenceError: Components is not defined
resource://jid0-7yp22cmsooypei7nicamg3n0ha0-at-jetpack/myfirstext/lib/main.js 57

我该如何解决?

【问题讨论】:

    标签: firefox-addon firefox-addon-sdk thunderbird thunderbird-addon error-console


    【解决方案1】:

    Thunderbird 提供了一个Application 接口,除其他外,它还有助于记录:

    var {Cc, Ci} = require("chrome");
    var Application = Cc["@mozilla.org/steel/application;1"]
                        .getService(Ci.steelIApplication);
    
    Application.console.log('Bam!');
    

    【讨论】:

    • 我不知道你在使用 Jetpack。我不确定这是否正在为 Thunderbird 积极开发。请测试我修改后的答案是否有帮助。
    • 是的,我发现我在尝试将 Jetpack 与 Thunderbird 一起使用时走错了路。我切换到传统的基于覆盖的扩展,现在可以了。
    • 在较新的雷鸟版本中是否仍然相关?喜欢50.* - 62.*?