简体   繁体   English

在自举的Firefox扩展中设置全局错误处理程序

[英]Setting up a global error handler in a bootstrapped firefox extension

I am building a bootstrapped extension for Firefox (not using the Add-on SDK since I need tcp sockets). 我正在为Firefox构建一个自举扩展(因为我需要tcp套接字,所以不使用附加SDK)。 Although all my IO calls etc. are protected by a try/catch, I want to have a global error handler just in case. 尽管我所有的IO调用等都受到try / catch的保护,但我还是希望有一个全局错误处理程序,以防万一。 Bootstrapped extensions do not have access to a window object so the window.onerror route is out of the question. 自举扩展不能访问window对象,因此window.onerror路由是不可能的。 Any suggestions as to how I can go about this? 关于如何解决这个问题有什么建议吗?

Thanks in advance. 提前致谢。

There is no such thing as a reliable global error handler. 没有可靠的全局错误处理程序。 Just wrap startup / shutdown ( install / uninstall ) in try-catch blocks. 只需将startup / shutdowninstall / uninstall )包装在try-catch块中。 You may also want to wrap global statements. 您可能还需要包装全局语句。

try {
  // do some fancy initialization... But you really shouldn't at the global scope.
}
catch (ex) {
  // handle/log error, e.g.
  Components.utils.reportError(ex);
}

function startup() {
  try {
    // Run
  }
  catch (ex) {
    // handle/log error, e.g.
    Components.utils.reportError(ex);
  }
}
function shutdown() …
// etc.

The extension manager will log failures with your bootstrap.js anyway (see the extensions.logging.enabled preference). 扩展管理器仍然会使用bootstrap.js记录故障(请参阅extensions.logging.enabled首选项)。

Aside: SDK add-ons can use the chrome module to gain access to low level stuff. 另外:SDK附加组件可以使用chrome模块来访问低级内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM