Advice on implementing my own console as an XPCOM
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 do开发者_运维技巧n'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 =)
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:
精彩评论