关于将我自己的控制台实现为 XPCOM 的建议
我想为我的扩展使用我自己的控制台,我将在其中打印出各种调试信息。我想我会通过执行
window.open("chrome://myextension/content/console.xul"..
然后打印到该窗口的文本框来做到这一点。您是否已经看到这里有问题=)
现在我有一个小问题, window.open 立即返回,如果我继续并立即使用 myconsole.log("boo") 函数,那么新打开的窗口中的内容尚未加载,我将得到错误。这意味着我必须等待控制台完成加载才能打印到它。正确的做法是什么?我可以在 log 方法中使用 nsITimer 或 thread.sleep 来继续检查它是否已加载,但我不喜欢这样。我也不知道如何正确使用 window.onload 事件,因为我看到的唯一方法是像 window.onload = function() { all of my extension code.. } 这样我也不喜欢。
我希望它能随时随地以某种方式使用它,
console = Cc["@myconsole;1"].getService().wrappedJSObject;
console.log("foo");
有什么建议吗?感谢您的耐心等待=)
I want to use my own console for my extension, where I would be printing out various debug info. I thought I would do that by doing
window.open("chrome://myextension/content/console.xul"..
and then printing into textboxes of that window. Do you already see something wrong here? =)
Now I have a small problem, window.open returns immediately and if I then go ahead and immediately use myconsole.log("boo") function, then the content in that newly opened window is not loaded yet and I will get errors. This means that I have to wait for the console to finish loading before I can print to it. What would be the right way of doing it? I could use nsITimer or thread.sleep inside of the log method to keep checking if it's loaded already, but I don't like this. I also don't know how I could correctly use window.onload event, because the only way I see is smth like window.onload = function() { all of my extension code.. } which I don't like either.
I want it to be used anytime anywhere somehow like this
console = Cc["@myconsole;1"].getService().wrappedJSObject;
console.log("foo");
Any advice? Thanks for the patience =)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会首先将其实现为后端日志记录模块:
https://developer.mozilla.org/en/ JavaScript_code_modules
然后编写一个与之交互的自定义 Chrome 窗口(获取所有日志、清除日志、订阅获取新日志事件)。
要节省编码时间,另请参阅 console2 和(最不为人知的)firebug 跟踪控制台:
I would have implemented it first as a backend logging module:
https://developer.mozilla.org/en/JavaScript_code_modules
And then write a custom chrome window which interacts with it (gets all logs, clear logs, subscribes to get new log events)
To save yourself coding time see also console2 and (the least known) firebug tracing console: