Debugging Javascript in Firefox
May 20, 2008I was playing around with PwdHash today, and I realized I couldn’t see the debug output (created with calls to the built-in function “dump()”). This was sufficiently complex to remedy that I’m making a note of it here.
Open a new tab and enter “about:config” for the address. Right click on any of the existing entries and select “New -> Boolean”. Create the following two booleans, set to true:
browser.dom.window.dump.enabled
javascript.options.showInConsole
This ends up putting these two lines into prefs.js, which lives somewhere in your profile directory:
user_pref(”browser.dom.window.dump.enabled”, true);
user_pref(”javascript.options.showInConsole”, true);
Don’t edit that file while Firefox is running or your changes will be overwritten. Also, using this ‘about:config’ method causes your changes to take effect right away, so no need to restart (or lose all your tabs!). This output goes to the unix console (stdout or stderr), so make sure you run your browser from a terminal. The Error Console viewable from the Tools menu displays more sophisticated errors. I’m only interested in printf()-style output for now.