Debugging JavaScript without alerts

I wrote a while back about logging tools for JavaScript and how some very powerful tools have been appearing lately.

Sometimes though, you don’t need all the power and complexity that a fully-fledged logger brings. Sometimes, you just want to know what’s happening at a certain point in your script — you might want to find out the value of a particular variable, for instance. In those cases, the humble alert function can be very handy.

Unfortunately, it can also be very annoying. It interrupts the flow of your script and once you’ve clicked the dialogue box away, there is no record of its contents.

Actionscript — the ECMAScript cousin to JavaScript, used in Flash — doesn’t use alert. Instead, it has a trace command. You can use trace in the same way as you’d use alert but the way it outputs messages is far more discrete.

Traced messages appear in a separate window. The flow of the script isn’t interrupted and you get a handy history of all the messages that have been output.

Wouldn’t it be great if JavaScript had something similar?

That’s what Aaron Gustafson thought. He’s come up with a really useful script called jsTrace.

All you have to do is include this script via script tags and you can then trace to your heart’s content. Once you’re done debugging, you can remove the reference to the jsTrace file, but you can still keep your trace commands in your code: they will silently fail without errors.

Have a play with the demo to see it in action. It’s also using Aaron Boodman’s DOM-Drag Library so that you can move the output window around the screen.

What I like about jsTrace is its simplicity. Like all the best applications, it does one thing really well. I think that scope-creep has ruined more than one potentially useful application and I’m glad to see that hasn’t happened here.

That said, if you have any ideas or suggestions for improvements, Aaron is all ears.

Posted by Jeremy on Sunday, October 30th, 2005 at 2:29pm


I am indeed "all ears," but, like you, I don’t want to see scope creep kill what is otherwise a very useful script. Helpful add-ons such as the delimeter, clear and Joe Shelby’s memory functionalities are more than welcome, but I’d like to keep it as bare bones as possible (which is why the styles are all set in the script… I want to keep it self-contained and discreet).

# Posted by Aaron Gustafson on Sunday, October 30th, 2005 at 3:54pm

A perhaps useful URL:

…and opera-9-specific:

# Monday, October 31st, 2005 at 11:30pm

Sorry. Comments are closed.

October 2005

Recommended Reading

XML Subscribe

Grab the RSS feed for this blog.

JavaScript API

Grab the RSS feed of comments for this entry.