How To Debug Web Applications With Firefox

Debugging is one of the most painful parts of developing web apps. You have to deal with browser inconsistencies with HTML, CSS and javascript, let alone the difficulty of debugging javascript itself.

Here’s a rundown of the Firefox extensions I use to manage this madness.

Taming CSS: Web Developer Toolbar

Install Web Developer Toolbar. Just do it.

Debugging CSS can be really frustrating. The Web Developer Toolbar lets you inspect and edit (in real-time) the HTML and CSS of your page, so you can see what’s happening when things don’t line up. It can do a heck of a lot more, but here’s what I use it for:

Ctrl + Shift + F: Display element information. This puts a red box under your mouse. Move the mouse over an element and its attributes appear in a pop-up: the name, class, pixel sizes, fonts, everything. Here’s what you can do:

  • Figure out what classes are creating the styles you see
  • Easily get the div’s id for use with Firebug (below)
  • Figure out how big an image is (pixel height and width)


Ctrl + Shift + E: Edit CSS. This pops open a sidebar tab with the current stylesheets. You can edit any attributes and see the effect in real-time (like giving Google a black background):


My favorite CSS style is border: 1px solid red;

I’ve done the following hundreds of times during the course of web development:

  • Find a div with your mouse (ctrl + shift + f)
  • Get its id
  • Edit CSS (ctrl + shift + e)
  • Put a border on the div: #mydiv{border: 1px solid red;}
  • Play with widths, heights, margins and paddings until it lines up nicely
  • Remove the border

But rather than deleting the border, put an “x” in front: “xborder: 1px solid red”. The CSS won’t be valid so the border is ignored, but keeps the style around in case you want to enable it later.

Select all the text in your edited CSS file and paste it into the real CSS file. Bam, your changes are now live. It’s almost the reverse of creating a file in DreamWeaver and viewing it in Firefox. You are viewing the live file in Firefox, making changes, and copying those back into your text editor. I’ve found this very effective for editing CSS, you avoid the constant back-and-forth switching because Firefox now has a CSS editor.

Bonus: ColorZilla Picks Colors

ColorZilla gives you a dropper that can find the hex RGB value (#123456) of anything on the page. This is great when designing, and you want to match a font color to a color in your page. This is way faster than taking a screenshot and opening it up in Photoshop.

Keeping Javascript In Line: Firebug

Firebug, how I love thee (or get the bookmarklet for other browsers). If you love yourself you will install it immediately and save countless hours of frustration.

Firebug can debug javascript, examine the DOM, and do much more (you can and should read all about it). Here’s how I use it:

F12: Open Firebug. You may have to enable it for the page.

Console Tab: Write quick javascript commands — it even has autocomplete on variable names and properties. Play around with your functions, change CSS attributes, add elements to the page — whatever it takes to test.

Script Tab (Debugging): Best. Feature. Ever. Click on a line number to set a breakpoint (red dot) in your javascript. Reload the page and it will break (pause) when it encounters the line.

At this point, you can switch over to the console to examine and change variables, and figure out what the heck is going on when your code won’t work. You can then hit the blue “play” button and continue running your app, until the next breakpoint.

Net Tab: Find the download performance of your page.

Profile Button (on Console Tab): Find the run-time performance of your page. Click “profile” to begin capturing information, do some commands, and then click stop. You’ll get a report of where your code spends its time. If you must optimize, optimize the common-case first.

If you are a more visual person, try this awesome collage:


Not satisfied? Check out the examples on the home page.

Dive into the details: Live HTTP Headers

Sometimes you need to dive into the nitty-gritty. What cache headers is my site sending back? Are my pages really gzip-encoded?

I know these questions keep you up at night, so here’s what you can do:

  1. Install Live HTTP Headers
  2. Open it (Tools > Live HTTP Headers)
  3. Visit a page / press refresh
  4. Rejoice


As you visit a page, you’ll see HTTP headers fly by as your browser requests elements. If items are cached, the browser may not request them at all (awesome!) or may request the element and get a 304 “Not Modified” response (slightly less awesome, you still had to check with the server). I’ve written more on cache behavior, and Live HTTP Headers is a great way to learn about HTTP caches (something every webdev should be interested in for performance reasons).

Even better, you can “replay” any header, editing the data that is sent. This is useful when testing or debugging cache or gzip encoding behavior.

Debugging IE: The lost chapter

Argh, unfortunately IE lacks these wonderful tools. There is a script debugger, but it doesn’t hold a candle to Firebug. In fact, I often just resort to alert statements, which make you shudder after being spoiled by Firebug.

One less painful method I use is this:

In your HTML: <div id="log"></div>

In your Javascript:

function log(str){
  var log = document.getElementById("log")
  if (log){ // let's be safe...
     log.innerHTML += str + "<br/>";

Usage: log("Hi there!");

Optional: create an eval box:
<input name="eval" id="eval"/>
<a href="javascript:void(0);" onClick="log(eval(document.getElementById('eval').value));">go</a>

It’s nothing fancy, just a simple logging function that appends text to a div. Yes, it’s brutal, but it’s better than alert() statements, especially if you have a loop (unless you like repetitive stress injuries or want to condition yourself to fear dialog boxes). If anyone knows a good way to debug javascript in IE I’d love to know. The tools I’ve tried have been very clumsy and disjoint, taking you out of the browser.

I try to do 95% of my development in Firefox, and debug IE-specific issues (like erratic substr behavior) using this method.

Keep Getting Better

Web Developer Toolbar and Firebug can do way more than I’ve described here. Like the 80/20 rule, these are commands I use most frequently that give me the best bang for my buck. Take a few minutes to learn these tools and you’ll save hours down the line. And here’s a few more tools for web development.

These tools might not save you from getting a nervous twitch in one eye from building web apps, and that’s ok. They’ll save you from getting that twitch in both.

Other Posts In This Series

  1. How To Optimize Your Site With HTTP Caching
  2. How To Optimize Your Site With GZIP Compression
  3. How To Debug Web Applications With Firefox
  4. Speed Up Your Javascript Load Time
  5. Speed Up Your Javascript, Part 2: Downloadable Examples!

How to run Java applications in command line?


主  题:How to run Java applications ?rn作  者:Kelvin9230rn所属论坛:Javarn问题点数:24rn回复次数:8rn人气指数:54rn发表时间:2001-8-10 11:09:48rn rnI use JBuilder2 to compile an application generated by application wizard. It outputs some class files. What I want to know is how can I use Java virtual machine to load the application and run it. I setup the environments correctlly. But, when I use jre.exe to run the application in command line, an error information will show: Class not found. I began to learn Java 3 days ago. So this information confuses me. Is there anyone who can tell me how to do ? I have referenced the help documents, but it does not work. rnrn rnrnrn回复贴子: rn hexiaofeng(java爱好者) 回复于2001-8-10 12:37:18 得24分 rnjavac j.javarnjava j rn panq() 回复于2001-8-10 12:43:02 得0分 rn把class所在的路径 设到classpath中rn如果是jdk1.3只用设path中rn rn kare(小李飞刀的飞,小李飞刀的刀。) 回复于2001-8-10 13:20:41 得0分 rnC:\Borland\jbuilder5\jdk1.3\bin\javaw -classpath "D:\Kare\AutoAnswer\classes;C:\Borland\jbuilder5\lib\jbcl.jar;C:\Borland\jbuilder5\lib\dx.jar;C:\Borland\jbuilder5\lib\beandt.jar;C:\Borland\jbuilder5\jdk1.3\demo\jfc\Java2D\Java2Demo.jar;C:\Borland\jbuilder5\jdk1.3\jre\lib\i18n.jar;C:\Borland\jbuilder5\jdk1.3\jre\lib\jaws.jar;C:\Borland\jbuilder5\jdk1.3\jre\lib\rt.jar;C:\Borland\jbuilder5\jdk1.3\jre\lib\sunrsasign.jar;C:\Borland\jbuilder5\jdk1.3\lib\dt.jar;C:\Borland\jbuilder5\jdk1.3\lib\tools.jar" yourPackage.mainclassname rnrn这是用JB5,JB2只需将相应的.jar及其路径改一下就可以了,建议你用JB5吧rn rn Kelvin9230() 回复于2001-8-10 13:23:50 得0分 rnTo : hexiaofeng(java爱好者)rnrnI successfully compiled, but can not run it. Error message are printed. I do what panq told me, but also failed.rnrnD:\java\proj\test>javac test.javarnAppAccelerator(tm) 1.1.034 for Java (JDK 1.1), x86 version.rnCopyright (c) 1998 Borland International. All Rights Reserved.rnrnD:\java\proj\test>java testrnAppAccelerator(tm) 1.1.034 for Java (JDK 1.1), x86 version.rnCopyright (c) 1998 Borland International. All Rights Reserved.rnCan't find class testrnrnD:\java\proj\test>rnrnThe following is the directory that contains my application.rnD:\java\proj\test>dirrnrnVolume in drive D is WINDOWS98rnVolume Serial Number is 1272-1BE2rnDirectory of D:\java\proj\testrnrn. 08-10-01 11:17 .rn.. 08-10-01 11:17 ..rnOPENFILE GIF 1,132 08-10-01 11:17 openFile.gifrnHELP GIF 118 08-10-01 11:17 help.gifrnCLOSEF~1 GIF 1,154 08-10-01 11:17 closeFile.gifrnTEST~1 CLA 1,149 08-10-01 13:11 test.classrnTEST~1 JAV 1,442 08-10-01 11:17 test.javarnFRAME~1 JAV 2,674 08-10-01 11:17 Frame.javarnFRAME~1 CLA 3,371 08-10-01 13:11 Frame.classrnFRAME_~2 JAV 3,102 08-10-01 11:17 Frame_AboutBox.javarnFRAME$~2 CLA 576 08-10-01 13:11 Frame$1.classrnFRAME$~3 CLA 577 08-10-01 13:11 Frame$2.classrnFRAME_~2 CLA 3,634 08-10-01 13:11 Frame_AboutBox.classrn 11 file(s) 18,929 bytesrn 2 dir(s) 29,360.34 MB freernrnD:\java\proj\test>rnrnTo panq:rnI do what you told me, but failed. My JDK is version 1.1rnrnHelp me please. I want to develop an internet browser using JAVA.rn rn hexiaofeng(java爱好者) 回复于2001-8-10 13:27:57 得0分 rnset classpath=%ClASSPATH%;.rnrn在运行试试 rn Kelvin9230() 回复于2001-8-10 13:30:08 得0分 rnTo kare(小李飞刀的飞,小李飞刀的刀。):rnrnThe following is my environments. I set it using the batch file "setvars.bat"rnrnD:\JBuilder2 is the directory where I install java builder.rnrnD:\java\proj\test>setrnTMP=C:\WINDOWS\TEMPrnTEMP=C:\WINDOWS\TEMPrnPROMPT=$p$grnwinbootdir=C:\WINDOWSrnCOMSPEC=C:\COMMAND.COMrnwindir=C:\WINDOWSrnBLASTER=A220 I5 D1 T4 P300rnPATH=D:\JBUILD~1\BIN;D:\JBUILD~1\JAVA\BIN;C:\WINDOWS;C:\WINDOWS\COMMANDrnCLASSPATH=.;d:\jbuilder2\bin;d:\jbuilder2\java\bin;d:\jbuilder2\lib\jbcl2.0.jar;rnd:\jbuilder2\lib\jbcl2.0-res.jar;d:\jbuilder2\lib\jgl3.1.0.jar;d:\jbuilder2\libswingall.jar;d:\jbuilder2\lib\datastore2.0.jar;d:\jbuilder2\lib\datastore2.0-resrn.jar;d:\jbuilder2\lib\jcbwt.jar;d:\jbuilder2\lib\jcchart.jar;d:\jbuilder2\lib\jcrntable.jar;d:\jbuilder2\lib\vbjorb.jar;d:\jbuilder2\lib\vbjapp.jar;d:\jbuilder2\lrnib\vbjgk.jar;d:\jbuilder2\lib\vbjtools.jar;d:\jbuilder2\samples;d:\java\classes;rnd:\java\proj;d:\jbuilder2\java\lib\;rnJAVA_COMPILER=javacomprnJAVA_HOME=d:\jbuilder2\javarnJBUILDER_HOME=d:\jbuilder2rnCMDLINE=java testrnrnD:\java\proj\test>rnrnrnrnI think that the environment is no ploblem.rnrn rn Kelvin9230() 回复于2001-8-10 13:34:56 得0分 rnTo hexiaofeng(java爱好者):rnrnFailed again. rn Kelvin9230() 回复于2001-8-10 13:52:24 得0分 rnSorry I do know how to add you score.rnThere is some mistake. rnrnrn 论坛