RTTP Log Firebug Extension


I recently put some time into developing a Firebug extension to display log messages From SL4B – Caplin’s Ajax Streaming Library. Usually these messages are displayed in a popup window that will close and re-open on every refresh of Caplin Trader.

Most of the developers at Caplin already have Firebug open during development anyway so why not incorporate something into Firebug while at the same time overcoming some of the annoyances of popup windows, and hopefully overcoming some of the performance implications of them at the same time?

There aren’t exactly a huge number of articles outlining Firebug extensions in detail, but I did manage to find a series of tutorials by Jan Odvarko that would prove to be useful. I also found digging through the Firebug source extremely useful.

My original plan was to detect when SL4B was available in the browser and then override the appropriate log method so that I would receive any log messages, primarily because I began development at home so didn’t have access to the SL4B source code. This method wasn’t adequate because even with a 10 ms timer, I would still miss the first few log messages.

Back to the drawing board, and digging deeper into the Firebug source code, I was attempting to find out how Firebug made methods such as console.info() and console.trace() available to the main window, then I came across this little gem:

<br>var val = Firebug.CommandLine.evaluateInWebPage(sSource, context, context.window);<br>

I found that Firebug ‘injects’ script into the host window and then uses an element and Firefox’s event API to receive messages from the webpage. With this in mind, I attempted to do the same:

<br>window.rttpFirebugLog = function(sMessage)<br>{<br>    var element = document.getElement('_rttpLog');<br><br>    var event = document.createEvent('Events');<br>    event.initEvent('rttpLogEvent', true, false);<br><br>    element.setAttribute('log', sMessage);<br>    element.dispatchEvent(event);<br>}<br>

The next step is to put this script into a file and get a reference to it from with the extension:

<br>var sSource = getResource('chrome://rttpLog/content/RttpLogInjected.js');<br>

Once that had been injected into the host window using Firebug.CommandLine.evaluateInWebPage, a reference to the element could be retrieved from the Firebug extension using the following:

<br>initContext: function(context, persistedState)<br>{<br>    var self = this;<br>    var element = context.window.document.getElementById('_rttpLog');<br>    element.addEventListener('rttpLogEvent', function(e) { self.onRttpLog(e)}, true);<br>},<br><br>onRttpLog: function(e)<br>{<br>    var sLog = e.target.getAttribute('log');<br>    var panel = FirebugContext.getPanel('RttpLog');<br>    panel.log(sLog);<br>}<br>

And that’s it! With this communication channel opened up, it was possible to make the rttpFirebugLog() method available to SL4B so that we could get the messages into a Firebug extension.

The extension itself allows you to chose which level of messages you’d like to see, and another neat feature I added was the ability to dynamically replace the protocol field identifiers with the real field names inline, making the logs easier to follow.

Following Jan’s series of articles you should be able to write something to a Firebug Panel, and make options available for the extension. The end result looks something like this:

RTTP Log Firebug Extension

Related Posts with Thumbnails

One Comment

Leave a Comment

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Anti-spam image