<?xml version="1.0" encoding="ISO-8859-1" ?>

<?xml-stylesheet type="text/xsl" href="/lib/xsl/devedge-1.00/article_en.xsl"?>
<nde:article 
  xmlns:nde="http://devedge.netscape.com/2002/de"
  url="/viewsource/2003/mozilla-webdev/"
  xmlns="http://www.w3.org/1999/xhtml"  
  xml:lang="en">

  <nde:header>
    <nde:title>Using Mozilla in Testing and Debugging Web Sites</nde:title>
    <nde:category>Article</nde:category>
    <nde:pubdate year="2003" month="04" day="11" />
    <nde:channels>
      <nde:channel id="viewsource" />
    </nde:channels>
  
    <nde:summary>
      Learn about features in Mozilla which allow you to quickly find and debug errors in your web site and web applications.
    </nde:summary>  
  
  </nde:header>

  <nde:head>
    <style type="text/css">
      .sourceCode {padding-left: 5px; padding-top:5px;}        
      .sourceView {margin: 5px; padding: 5px; border: 1px dashed grey; font-family: Verdana,sans-serif;}
      .sourceInfo {padding-bottom: 5px; font-size: 0.9em; padding-right: 5px; border-bottom: 1px dashed gray; border-right: 1px dashed gray;}
      .tb2 {position:absolute; left:20%;}
      .tb3 {position:absolute; left:66%;}     
#nde-pubmod {margin-bottom: 0 !important;}
#nde-author {margin-bottom: 2em !important;}
    </style>
  </nde:head>

  <nde:content>
     <ul class="nde-metadata" id="nde-author">
       <li>Henrik Gemal</li>
       <li>© Copyright 2003 Henrik Gemal.  <a href="http://gemal.dk/mozilla/mozdev.html">Reprinted</a> with permission.</li>
     </ul>
  
  
    <p>
      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.
    </p>  
  
    <p>
      In this article I will describe some very cool features in Mozilla which will enable you to quickly find and debug errors in your 
      web site and web applications.
    </p>
    
    <p>    
      While writing this article I have been using Mozilla 1.4a and Internet Explorer 6.0 SP1 on a Windows XP.
    </p>  
  
    <p>
      If you have any feedback you're more than welcome to <a href="http://gemal.dk/contact/feedback.cgi?section=mozilla">contact me</a>.
    </p>  
  
    <h2>JavaScript Console</h2>
  
    <p>
      A lot of the errors found in today's web pages and web applications are caused by JavaScript errors. Most of the time they're very 
      simple errors. This is in my opinion the most common reason why sites doesn't work in Mozilla. But these errors could easily be 
      avoided.
    </p>
    
    <p>    
      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 <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=2f465be0-94fd-4569-b3c4-dffdf19ccd99">Microsoft Script Debugger</a> 
      which is a debugging environment for scripting in Internet Explorer.     
    </p>
    
    <p>
      <img src="mozdev01.png" alt="Javascript error in Internet Explorer" /><br />
      <strong>Picture 1: JavaScript error in Internet Explorer</strong>
    </p>

    <p>
      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.
    </p>

    <p>
      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. 
    </p>
    
    <p>
      <img src="mozdev02.png" alt="The Mozilla JavaScript Console with errors" /><br />
      <strong>Picture 2: The Mozilla JavaScript Console with errors</strong>
    </p>
    
    <p>
      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.
    </p>
    
    <p>    
      The JavaScript Console can be started via <em>Tools -> Web Development -> JavaScript Console</em>.
    </p>
    
    <h2>JavaScript Strict Warnings</h2>

    <p>
      JavaScript strict warnings are messages that are produced inside the JavaScript Engine, which is in the core of the browser. 
      JavaScript strict warnings are produced in all browsers - Mozilla, Internet Explorer and Opera. But only Mozilla shows 
      them.
    </p>  

    <p>
      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.     
    </p>

    <p>
      <img src="mozdev03.png" alt="JavaScript strict warnings" /><br />
      <strong>Picture 3: JavaScript strict warnings</strong>
    </p>    
    
    <p>
      In other browsers than Mozilla these exceptions 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!
    </p>  

    <p>
      A common mistake in JavaScript is to declare a variable twice: <br />
      
      &#160;&#160;<strong>var response = true;</strong><br />
      &#160;&#160;<strong>var response = false;</strong><br /><br />

      This will produce a JavaScript strict warning saying<br />

       &#160;&#160;<strong>"redeclaration of var response"</strong><br /><br />
 
      The correct way is of course:<br />
 
       &#160;&#160;<strong>var response = true;</strong><br />
       &#160;&#160;<strong>response = false;</strong><br />
    </p>
    
    <p>
      The JavaScript Console can be enabled in nightly builds via <em>Edit -> Preferences -> Debug -></em>. If you run an official release you can 
      use the <em>javascript.options.strict</em> pref which can be set by entering <em>about:config</em> in the Location and hitting enter.
    </p>
    
    <h3>More info...</h3>
    <ul>
      <li><a href="http://wsabstract.com/javatutors/serror.shtml">Tackling JavaScript strict warnings</a></li>
    </ul>
    
    <h2>Cookie Control</h2>  
  
    <p>
      Most web sites and web applications nowadays are using cookies. Debugging cookies can be a problem. But not if you use Mozilla.
    </p>  
  
    <p>
      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. Since the files are in an unknown text format I'm not sure if you can delete or edit specific cookies from a site or 
      domain. 
    </p>

    <p>
      <img src="mozdev04.png" alt="Cookie Manager in Internet Explorer" /><br />
      <strong>Picture 4: Cookie Manager in Internet Explorer</strong>
    </p>      

    <p>
      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.
    </p>
    
    <p>
      <img src="mozdev05.png" alt="Cookie Manager in Mozilla" /><br />
      <strong>Picture 5: Cookie Manager in Mozilla</strong>
    </p>
    
    <p>
      Both browsers 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.
    </p>
    
    <p>
      <img src="mozdev06.png" alt="Cookie Dialog in Mozilla" /><br />
      <strong>Picture 6: Cookie Dialog in Mozilla</strong>
    </p>
    
    <p>
      <img src="mozdev07.png" alt="Cookie Dialog in Internet Explorer" /><br />
      <strong>Picture 7: Cookie Dialog in Internet Explorer</strong>
    </p>
    
    <h2>View Source with Color Highlight</h2>
    
    <p>
      One of the most used features of web developers is the view source. Mozilla has some very nice color coding features while you 
      have to look elsewhere to get the same in Internet Explorer.
    </p>
   
    <p>
      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.     
    </p>    
    
    <p>
      <img src="mozdev08.png" alt="Notepad with the source of gemal.dk" /><br />
      <strong>Picture 8: Notepad with the source of gemal.dk</strong>
    </p>
    
    <p>
      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.
    </p>
    
    <p>
      <img src="mozdev09.png" alt="View Source with Color Highlight of the source of gemal.dk" /><br />
      <strong>Picture 9: View Source with Color Highlight of the source of gemal.dk</strong>
    </p>

    <p>The View Source can be seen via <em>View -> Page Source.</em></p>
    
    <h2>View Selection Source</h2>

    <p>
      If you use document.write in your JavaScript, then you are probably familiar with the problem of not being able to see the 
      content generated by it.
    </p>
    
    <p>
      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.
    </p>
    
    <p>
      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 
      <a href="http://bugzilla.mozilla.org/show_bug.cgi?id=60426">improvements</a> being worked on for the View Source window so that it can switch between generated and source HTML. 
    </p>    
    
    <p>
      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.
    </p>
    
    <p>
    <pre><strong>
for (var i = 0; i &lt; 10; i++) {
&#160;&#160;document.writeln('&lt;span id="id-"' + i + '"&gt;test: ' + i + '&lt;/span&gt;');
&#160;&#160;for (var j = 0; j &lt; 5; j++) {
&#160;&#160;&#160;&#160;document.write(j + '&lt;br&gt;');
&#160;&#160;}
}
      </strong></pre>
    </p>

    <p>
      <img src="mozdev10.png" alt="The source of a selection" /><br />
      <strong>Picture 10: The source of a selection</strong>
    </p>

    <h2>Page Info</h2>
  
    <p>
      Both Internet Explorer and Mozilla have the ability to show the properties about the current page. <br />

      In Internet Explorer this is done via File -> Properties. The information show is very limited. 
    </p>

    <p>
      <img src="mozdev11.png" alt="Page info in Internet Explorer" /><br />
      <strong>Picture 11: Page info in Internet Explorer</strong>
    </p>
    
    <p>
      In Mozilla you have access to a whole bunch of information about the current page.
    </p>

    <p>
      <img src="mozdev12.png" alt="Page info in Mozilla" /><br />
      <strong>Picture 12: Page info in Mozilla</strong>
    </p>
    
    <p>
      The Page Info can be seen via <em>View -> Page Info</em>.
    </p>

    <h2>JavaScript Debugger</h2>
    
    <p>
      Venkman is Mozilla's JavaScript Debugger. Venkman provides a powerful JavaScript debugging environment. Venkman is both a GUI 
      and a console debugger. Features such as breakpoint management, call stack inspection, and variable/object inspection are 
      available from the user interface and as console commands, letting you work in the way you feel comfortable. The interactive 
      console also allows for execution of arbitrary JavaScript code. Venkman's keyboard shortcuts are the same as leading visual 
      debugging environments, and <a href="http://sources.redhat.com/gdb/">gdb</a> users should be familiar with Venkman's break, step, 
      next, finish, frame, and where commands.
    </p>

    <p>
      <img src="mozdev13.png" alt="Mozilla's JavaScript Debugger" /><br />
      <strong>Picture 13: Mozilla's JavaScript Debugger</strong>
    </p>
    
    <p>
      The JavaScript Debugger also supports profiling. Profiling can be used to measure execution times for your JavaScripts. <br />

      The JavaScript Debugger can be started via <em>Tools -> Web Development -> JavaScript Debugger</em>.
    </p>
    
    <h3>More info...</h3>
    <ul>
      <li><a href="http://devedge.netscape.com/viewsource/2002/venkman/01/">Introduction to the JavaScript Debugger at DevEdge</a></li>
      <li><a href="http://www.mozilla.org/projects/venkman/">Venkman at mozilla.org</a></li>
      <li><a href="http://www.hacksrus.com/%7Eginda/venkman/">Venkman Development</a></li>
    </ul>    
    
    <h2>HTTP Headers</h2>
    
    <p>
      One of the best extensions to Mozilla is the Live HTTP Headers. This extension gives you the ability to view the HTTP headers that 
      are passed between your browser and the web server. If you for example are trying to debug a cookie problem or a MIME header 
      problem you can view all the details of the HTTP headers with this extension.
    </p>

    <p>
      <img src="mozdev14.png" alt="Live HTTP Headers console" /><br />
      <strong>Picture 14: Live HTTP Headers console</strong>
    </p>
    
    <p>
      Once installed the Live HTTP Headers can be started via <em>Tools -> Web Development -> Live HTTP Headers</em>.
    </p>
    
    <h3>More info..</h3>
    <ul>
      <li><a href="http://livehttpheaders.mozdev.org">LiveHTTPHeaders at mozdev.org</a></li>
    </ul>
    
    <h3>DOM Inspector</h3>
    
    <p>
      DOM Inspector is a tool that can be used to inspect and edit the live DOM of any web document or XUL application. The DOM 
      hierarchy can be navigated using a two or three paned window that allows for a variety of different views on the document and all 
      nodes within. You can also view style sheets, rules, etc, not just DOM.
    </p>
    
    <p>
      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. 
    </p>

    <p>
      <img src="mozdev15.png" alt="Mozilla's DOM Inspector" /><br />
      <strong>Picture 15: Mozilla's DOM Inspector</strong>
    </p>
    
    <p>The DOM Inspector can be started via <em>Tools -> Web Development -> DOM Inspector</em>.</p>
    
    <h3>More info..</h3>
    <ul>
      <li><a href="http://www.mozilla.org/projects/inspector/">DOM Inspector at mozilla.org</a></li>
      <li><a href="http://www.brownhen.com/DI.html">Introduction to the DOM Inspector</a></li>
      <li><a href="http://grayrest.com/moz/evangelism/tutorials/dominspectortutorial.shtml">grayrest's Guide to the DOM Inspector for Web Developers</a></li>
    </ul>
             
    <h2>Cache Manager</h2>
    
    <p>
      The cache manager in Mozilla provides you with full access to see what's in the memory and disk cache. You can see all kind of 
      details about all cache entires. This could, for example, help you, as a developer, to verify that the headers sent out by a web 
      application are correct.
    </p>

    <p>
      <img src="mozdev16.png" alt="Cache Manager entry in Mozilla" /><br />
      <strong>Picture 16: Cache Manager entry in Mozilla</strong>
    </p>    
    
    <p>
      The Cache Manager can be started by entering <em>about:cache</em> in the Location and hitting enter.
    </p>
    
    <h2>Composer</h2>
    <p>
      The Mozilla suite also includes a full-fledged HTML editor for writing web pages. This article does not dicuss Mozilla Composer because most web developers 
      have their own prefered HTML editor.    
    </p>    
    
    <h2>Conclusion</h2>
    
    <p>
      As a web developer I simply just can't live without Mozilla. The web development and debugging tools that are in Mozilla are 
      excellent tools for debugging and testing web sites and applications.
    </p>
    <p>    
      If you have any feedback you're more than welcome to <a href="http://gemal.dk/contact/feedback.cgi?section=mozilla">contact me</a>.
    </p>
    
</nde:content>

  
</nde:article>
