Tuesday, November 11th, 2008
Firebug tricks, Dojo style
Tom Trenka has a nice posting on Dojo and Firebug Tricks for Development where he shares two of his own:
Trick #1: using window.location.search to enable Firebug Lite on the fly
With the Dojo Toolkit, I find this trick indispensable. The basic concept is to use the original version of the djConfig variable—the object-based one—using a boolean to enable or disable debugging.
In a single line of code, here’s the trick:
-
-
var djConfig = { isDebug: (window.location.search.indexOf("debug")>-1) };
-
Trick #2: setting up a simple HTML file that just enables the console
Once you drop in the simple HTML file below, you can bookmark it, load up your Dojo world, and then start to use Firebugs "Run" command to access Dojo-ness.
Start with this:
And then "Run" something like this:
-
-
dojo.require("dojox.xml.DomParser");
-
-
var xml='<?xml version="1.0"?>'
-
+ '<root><node>My first node</node>'
-
+ '<node>My second node</node>'
-
+ '</root>';
-
var doc=dojox.xml.DomParser.parse(xml);
-
console.log(doc);
-

What tips and tricks do you have?












Why not use a bookmarklet, it’s easy, and it’s work:
Just Bookmark this in firefox
javascript:var%20firebug=document.createElement(’script’);firebug.setAttribute(’src’,'http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js’);document.body.appendChild(firebug);(function(){if(window.pi&&window.firebug){firebug.init();}else{setTimeout(arguments.callee);}})();void(firebug);
And just hit this bookmark if you need FireBug Lite
This is a really good idea, and helps when your project reaches production and is on the client server. When they approach you with the inevitable bug, you can go to their site, and add ‘debug’ to the url to help with the inspection.
Jonat,
The reason a bookmarklet is not enough is that you often want to debug code that runs on page startup. With a bookmarklet you can only enable debugging after the page has finished loaded.
Toms approach turns on debugging before any code runs, so you get the debug output from both pre and post page loads.
Shane
I use the bookmarklet trick, too. This is a cool trick.