Mozilla is a great tool to use in developing web sites and web applications. Not as a development tool itself, like an editor, but as a testing and debugging tool. Here I describe some very cool features in Mozilla which will enable you to quickly find and debug errors in your web site and web applications. Used applications have been using Mozilla 1.4a and Internet Explorer 6.0 SP1 on Windows XP.
This page is also available in the following languages: French, Simplified Chineses
With Internet Explorer you are, if you have set the correct setting, presented with an almost useless dialog that "page contains errors". The dialog doesn't let you copy the error to the clipboard for starters. If you want better debugging in Internet Explorer you can install the Microsoft Script Debugger which is a debugging environment for scripting in Internet Explorer.
Picture 1: JavaScript error in Internet Explorer
With Mozilla on the other hand you have the JavaScript Console. All JavaScript errors are logged here. So if you keep the JavaScript Console open while testing your site you can on-the-fly see if there are any JavaScript errors. An indispensable tool for developing web sites and web applications.
The JavaScript Console reports the error and the filename and the line number. Furthermore the context of the error is shown. This makes it very easy to get a clue about where the error is and what caused it.
Picture 2: The Mozilla JavaScript Console with errors
You can right-click on each error and copy it to the clipboard. The JavaScript Console could still need a lot of improvements. You can't save all entires to a file and it has problems with wrapping.
The JavaScript Console can be started via Tools -> Web Development -> JavaScript Console.
JavaScript strict warnings are warnings from the JavaScript Engine about some mistakes in the client side JavaScript code. These mistakes, unlike JavaScript errors, do not stop the execution of the web page. But they do slow it down a bit, since they produce an exception inside the JavaScript Engine.
Picture 3: JavaScript strict warnings
In other browsers than Mozilla these exception are not available to the developer but with Mozilla you can access these warnings. This puts you in the driver seat for making 100% valid JavaScript code!
A common mistake in JavaScript is to declare a variable twice:
var response = true;
var response = false;
This will produce a JavaScript strict warning saying
"redeclaration of var response"
The correct way is of course:
var response = true;
response = false;
The JavaScript Console can be enabled in nightly builds via Edit -> Preferences -> Debug -> Show Strict JavaScript Warnings. If you run a official release you can use the javascript.options.strict pref which can be set by entering about:config in the Location and hitting enter.
In Internet Explorer you can't see the current cookies. At least not from within Internet Explorer. So if you're using Internet Explorer the only option you have from within Internet Explorer is to delete all current cookies. If you want to delete all cookies from a specific domain you have to manually delete the Internet Explorer cookie files which are located in the %USERPROFILE%/Cookies directory (using Windows XP). Since the files are in a unknown text format I'm not sure it you can delete or edit specific cookies from a site or domain.
Picture 4: Cookie Manager in Internet Explorer
With Mozilla it's all different. You have full control over the cookies. Both when they are being set and after. You can use the Cookie Manager to see all the currently set cookies. From the Cookie Manager you can delete selected cookies.
Picture 5: Cookie Manager in Mozilla
Both browser have dialogs to get control over which cookies should be set and which should be blocked. The dialogs look almost identical. But Mozilla's is a bit better. It remembers the state of the cookie information. If you left the more information part open it will stay open the next time the dialog comes up. In Internet Explorer you have to press the More Info button everytime.
Picture 6: Cookie Dialog in Mozilla
Picture 7: Cookie Dialog in Internet Explorer
Internet Explorer defaults to showing view source with Notepad. Notepad is the most simple application in the entire Windows environment. A very very simple text editor.
Picture 8: Notepad with the source of gemal.dk
In Mozilla you use the built in view source feature, which has color coding. This makes is very easy to get a quick overview of the structure of the HTML file.
Picture 9: View Source with Color Highlight of the source of gemal.dk
The View Source can be seen via View -> Page Source.
The problem normally arises when you write out HTML tags from inside JavaScript. In Internet Explorer it's very difficult to see the produced HTML from the scripts. You can only see the script itself. The problem is normally fixed by using a lot of JavaScript alerts.
But Mozilla has a very nice feature can can save you a lot of alert commands. It's called View Selection Source. Mark the text you want to see the source for and right-click and select View Selection Source. Netscape 4 had a similar option. There also improvements being worked on for the View Source window so that it can switch between generated and source HTML.
The following is an example where the quote is placed the wrong place and it's almost impossible to find without the selection source option.
for (var i = 0; i < 10; i++) {
document.writeln('<span id="id-"' + i + '">test: ' + i + '</span>');
for (var j = 0; j < 5; j++) {
document.write(j + '<br>');
}
}
Picture 10: The source of a selection
In Internet Explorer this is done via File -> Properties. The information show is very limited.
Picture 11: Page info in Internet Explorer
In Mozilla you have access to a whole bunch of information about the current page.
Picture 12: Page info in Mozilla
The Page Info can be seen via View -> Page Info.
Picture 13: Mozilla's JavaScript Debugger
The JavaScript Debugger also supports profiling. Profiling can be used to measure execution times for your JavaScripts.
The JavaScript Debugger can be started via Tools -> Web Development -> JavaScript Debugger.
Picture 14: Live HTTP Headers console
Once installed the Live HTTP Headers can be started via Tools -> Web Development -> Live HTTP Headers or View -> Page Info -> Headers.
In the screenshot below you can see that a red square with the text Home is highlighted. This text is shown in the DOM tree.
Picture 15: Mozilla's DOM Inspector
The DOM Inspector can be started via Tools -> Web Development -> DOM Inspector.
Picture 16: Cache Manager entry in Mozilla
The Cache Manager can be started by entering about:cache in the Location and hitting enter.