Hackzilla.org

November 22, 2008

Firefox Addon: Html Validator

Filed under: Hacking, Software — Dan @ 11:53 pm

Note: This tutorial is based on Html Validator version 0.8.5.2. The details outlined below may not work in future versions.

When I make web sites, I use quite a few different Firefox extensions.

One of the extensions that I use is called Html Validator https://addons.mozilla.org/en-US/firefox/addon/249

This extension is great.
It main use is to validator the html code when you "view source" in Firefox.
It also has secondary benefit is syntax highlighting.

Html Validator in action.

The Problem

However there is one problem that makes my job harder.

Error: oTidyBrowser is not defined
Source File: chrome://tidy/content/tidyBrowser.js
Line: 220

This shows up countless times in Firefox’s error console, making the job of finding other errors really hard.

I am going to show you how to stop this error.
(If this bug isn’t fix in the latest release, then you have to reapply this patch)

Solution to "oTidyBrowser is not defined"

The first step is locating the above file.

I can’t give you direct link to it, because of Firefox stores it in profile folder.
The Firefox profile folder, which will have a different name.

My Html Validator location is:
C:\Users\Dan\AppData\Roaming\Mozilla\Firefox\Profiles\vqy7rs08.default\extensions\{3b56bcc7-54e5-44a2-9b44-66c3ef58c13e}\chrome

Clicking on the file, "chrome://tidy/content/tidyBrowser.js," in the error console, will bring up the source code for this file.
The title of the window will be actual file path to the file in question.

When you get to the chrome folder you will be looking for a file called "tidy.jar"

The file "tidy.jar" is really a zip file.

Now duplicate this file and call it "tidy.zip".

Open "tidy.zip" in your

favourite file compression utility (Try Winzip or Winrar, if you don’t have one).

You now need to edit the file "content/tidyBrowser.js".

The section of code you are looking for is:

  1. if( oTidyBrowser.bTopLoadBusy==false )
  2. {
  3.  oTidyUtil.tidy.log( ‘<javascript>tidyEndDocumentLoadObserver’ );
  4.  oTidyBrowser.bTopLoadBusy = true;
  5.  try
  6.  {
  7.   // Validate the 1rst request
  8.   oTidyBrowser.bIgnorePageShow = true;
  9.   oTidyBrowser.validateFrame( window.content );
  10.   // oTidyBrowser.validateCache( subject.document, true );
  11.  
  12.   // Process the events that fired during the 1rst one
  13.   // ex: page with frames.
  14.   var doc = oTidyBrowser.oEventQueue.pop();
  15.   while( doc )
  16.   {
  17.    oTidyBrowser.validateCache( doc, true );
  18.    doc = oTidyBrowser.oEventQueue.pop();
  19.   }
  20.  }
  21.  catch(ex)
  22.  {
  23.   tidyShowExceptionInConsole( ex );
  24.  }
  25.  oTidyBrowser.bTopLoadBusy = false;
  26. }
  27. else
  28. {
  29.  // Parallel events are placed in a event queue.
  30.  oTidyBrowser.oEventQueue.push( event.originalTarget );
  31. }

What you need to do is add an if statement to check if "oTidyBrowser" is not defined.
This will have the effect of stopping the error from appearing in the error console.

  1. if( !window.oTidyBrowser )
  2. {
  3.  // Do nothing
  4. }
  5. else if( oTidyBrowser.bTopLoadBusy==false )
  6. {
  7.  oTidyUtil.tidy.log( ‘<javascript>tidyEndDocumentLoadObserver’ );
  8.  oTidyBrowser.bTopLoadBusy = true;
  9.  try
  10.  {
  11.   // Validate the 1rst request
  12.   oTidyBrowser.bIgnorePageShow = true;
  13.   oTidyBrowser.validateFrame( window.content );
  14.   // oTidyBrowser.validateCache( subject.document, true );
  15.  
  16.   // Process the events that fired during the 1rst one
  17.   // ex: page with frames.
  18.   var doc = oTidyBrowser.oEventQueue.pop();
  19.   while( doc )
  20.   {
  21.    oTidyBrowser.validateCache( doc, true );
  22.    doc = oTidyBrowser.oEventQueue.pop();
  23.   }
  24.  }
  25.  catch(ex)
  26.  {
  27.   tidyShowExceptionInConsole( ex );
  28.  }
  29.  oTidyBrowser.bTopLoadBusy = false;
  30. }
  31. else
  32. {
  33.  // Parallel events are placed in a event queue.
  34.  oTidyBrowser.oEventQueue.push( event.originalTarget );
  35. }

Now save tidyBrowser.js back to "tidy.zip".

At this point you will need to close Firefox, as it will currently have locked the original file.

You can now either delete "tidy.jar" or rename it.
Renaming the file is good idea, as you you can easily revert back if you encounter problems.
Rename "tidy.zip" to "tidy.jar".

Now you can restart Firefox.
You will now no longer suffer the error message, "oTidyBrowser is not defined".

Cheat

If you want to save time, you can download "tidy.jar", to replace your own copy.

I can’t make any warrenties to the file’s safety. If there is any doubt use my instructions.

Use this file at your own risk.

24 Comments »

  1. Awesome, thank you so much!!

    Comment by Richard — November 23, 2008 @ 3:45 am

  2. You shouldn’t need to do the if/else statement.

    The code could start like this:

    if( window.oTidyBrowser )
    if( oTidyBrowser.bTopLoadBusy==false )
    and so on…

    The first if statement checks for window.oTidyBrowser to be true, if it is then it carries on to the next if statement. If it is not true then it just skips it.

    This is a common way to test for an element to make sure it exists in the DOM before attempting to run code on it.

    I haven’t actually tried this but I see no reason it wouldn’t work. Your method is sound as well, it’s just a preference kind of thing. I’ve just never liked to have an empty if statement to only use the following else block.

    Comment by Travis Almand — November 24, 2008 @ 8:12 pm

  3. Awesome! Way to make it happen.

    Comment by Joe — November 25, 2008 @ 5:35 pm

  4. @Travis: I tend to not like empty if’s as well.
    I was considering writing it differently, but decided to keep it simple.

    However your method is the simplest yet.

    Hopefully the author will fix this problem.

    Comment by Dan — November 29, 2008 @ 10:11 pm

  5. Hi,

    Man thank you is not enough, that error was killing me. Thanks a lot

    Regards
    Nawaf

    Comment by Nawaf — December 11, 2008 @ 4:49 pm

  6. Man, this is some hack.
    You just made my day.
    Thnx

    Comment by Jools — December 12, 2008 @ 10:03 am

  7. .. I prefer this form …

    if(!window.oTidyBrowser) return;

    No need to worry about what the rest of the code does, no chance to break nested ifs later.

    Embrace return anywhere, continue and break – they are your friends!

    Comment by darkpenguin — January 6, 2009 @ 2:09 pm

  8. Thank you!! :)

    Comment by SiriuS — January 9, 2009 @ 11:31 am

  9. works great. many thanks

    Comment by Leuchte — January 31, 2009 @ 7:41 pm

  10. The bug is still there in the version 0.8.5.3 of Tidy.

    How to easily find tidy.jar:
    Just search for it in the ‘Users’ (Vista) or ‘Documents and Settings’ (XP) folder.
    You may also do:
    1. cd %appdata%\Mozilla\Firefox\Profiles
    2. cd
    3. cd extensions
    4. search here :-)

    Comment by nb000 — February 10, 2009 @ 3:13 pm

  11. Oh, man, you save the hundreds of our wasted hours! Fame on you!

    Comment by Andrew — February 14, 2009 @ 7:43 pm

  12. [...] Hackzilla.org » Firefox Addon: Html Validator [...]

    Pingback by oTidyBrowser is not defined を解決する | MEKEKEMORA — February 17, 2009 @ 6:45 am

  13. [...] Hackzilla.org » Firefox Addon: Html Validator [...]

    Pingback by oTidyBrowser is not defined を解決する | MEKEKEMORA — February 17, 2009 @ 6:45 am

  14. [...] on a completely different sidenote, using this page I finally fixed  the annoying console error messages that plague Firefox with Firebug and HTML [...]

    Pingback by | Maister.org.uk — February 24, 2009 @ 6:14 pm

  15. aaa

    Comment by Anonymous — March 10, 2009 @ 3:05 pm

  16. Ran across this a little late, but for those that don’t like the empty if/else statement:

    if (oTidyBrowser && oTidyBrowser.bTopLoadBusy==false)

    seems to work fine.

    Thanks for posting the fix to this, it was driving me mad.

    Comment by 5c11 — March 24, 2009 @ 7:59 pm

  17. Sorry, that should be:

    if (window.oTidyBrowser && oTidyBrowser.bTopLoadBusy==false)

    Thanks again.

    Comment by 5c11 — March 24, 2009 @ 8:11 pm

  18. thanks!!!!!!

    Comment by tom skinner — March 28, 2009 @ 9:36 pm

  19. worked on os x.

    i spent 8 hours rewriting our javascript compression library (symfony plugin coming soon?) to troubleshoot this. wish i had googled “oTidyBrowser is not defined” sooner.

    cd /Users//Library/Application Support/Firefox/Profiles/owhmypsz.default/extensions/{3b56bcc7-54e5-44a2-9b44-66c3ef58c13e}/chrome

    cp tidy.jar tidy.bak.jar

    mkdir tmp
    cd tmp
    unzip ../tidy.jar
    (edit the offending file in your favorite editor)
    cd ..
    zip -r tidy.jar tmp

    (restart firefox)

    Comment by mark meves — March 30, 2009 @ 2:28 pm

  20. [...] many other bloggers have pointed out, there is a bug in the Html Validator extension source code. You [...]

    Pingback by Jamey » oTidyBrowser is not defined — March 31, 2009 @ 11:03 am

  21. ok , just to make this more complicated, i actually needed to make the zipped folder (tidy.jar) from within the tmp folder.

    cd tmp
    zip -r ../tidy.jar .

    Comment by Mark Meves — April 14, 2009 @ 8:31 pm

  22. Thanks a million – this kind of stuff is fantastically useful

    Comment by Richard — April 27, 2009 @ 9:32 pm

  23. good article!

    Comment by misha — February 4, 2010 @ 2:19 pm

  24. Usually, teachers want to testify the term paper format writing ability of some their students, however not all good students can to write correctly because of lack of time or other things. Therefore, a essay writing service would aid to accomplish the term paper format professionally.

    Comment by OliviaTV29 — February 19, 2010 @ 2:30 am

RSS feed for comments on this post. TrackBack URI

Leave a comment

Powered by WordPress

Ofdan Statistics Technology Blogs - Blog Top Sites