You are currently viewing a snapshot of taken on April 21, 2008. Most of this content is highly out of date (some pages haven't been updated since the project began in 1998) and exists for historical purposes only. If there are any pages on this archive site that you think should be added back to, please file a bug.

Javascript Debugging

Ben Bucksch

This document is intended to help developers writing JavaScript code in Mozilla, mainly for Mozilla itself, but it may also be useful for web developers. It should give pointers to tools, aids and tricks which make debugging your code easier.

  • JavaScript Console
    First thing you should check when there's a problem. To be found under Tools|Web development|JavaScript console.
  • JavaScript Debugger (Venkman)
    Allows you to stop a script at predefined breakpoints, inspect variables etc.. A walkthrough explains its use.
  • DOM Inspector
    Shows the current state of the DOM (page/dialog structure as objects). Other modes of the right pane show the styles applied to the elements as well as the associated JavaScript objects. The button on the top left allows you to pick an element in the live page. With Ctrl-Shift-I, you can inspect the page currently loaded in the browser.
  • strict code checking
    If you set the pref "javascript.options.strict" to true, the JavaScript engine gives you more types of warnings on the JavaScript console, most of which hint at code bugs that are easy to oversee or even bad syntax.
  • dump()
    Allows you to print text on the native console. Use \n to output a newline at the end. To see anything, you need to set the pref "browser.dom.window.dump.enabled" to true, e.g. in <about:config>; and to have a native console at all under MS Windows, you need to start Mozilla via mozilla.exe -console. Using normal JS object inspection, you can write a function that dumps a whole object, similar to this ddumpObject().
  • Call stack
    You can print the current call stack (which functions were called to reach the current point) using the keyword debugger. You can also try using Components.stack, which presumably only works in Mozilla from chrome (not webpages).