Pete Freitag Pete Freitag

JavaScript Debugging with Safari

appleweb

If your doing web development or testing on Safari, JavaScript exceptions are quiet, like they are on most modern browsers (remember the days of annoying javascript error popups?). After looking around in the menus, or trying to type javascript: in the location bar (this brings up the javascript console in mozilla) you will soon find that there is no way to see your JavaScript exceptions by default.

Safari does in-fact have some handy debugging tools for web developers (DOM Tree, User Agent Spoofing, etc), but they are all hidden and disabled by default. The easiest way to turn on the debugging menu in safari is by installing Safari Enhancer.

Safari Enhancer Screen Shot

Make sure you check the box Debugging Menu, you can see that there are also some other handy features in Safari Enhancer. Click Apply Lasting Setting when your done.

Safari should reload and you will have a new menu called Debug

Screen Shot of Safari Debug Menu

Check Log JavaScript Exceptions in the debug menu. Now javascript exceptions will show up in your Console log (Applications / Utilities / Console).


Like this? Follow me ↯

JavaScript Debugging with Safari was first published on February 17, 2005.

Comments

Well, if you call things like ":TypeError - Undefined value" a useful error message... No line number, no source code, nothing useful really.
by Bertrand Le Roy on 02/22/2005 at 9:47:34 PM UTC
how about this:

(event handler):Undefined value

yeah, that's greatly helpful. Thanks Apple!
by jay on 03/07/2005 at 11:29:58 AM UTC
I get "SyntaxError - Parse error Line 1". Really useful. </sarcasm>

Considering that Safari's scripting support is pretty-much as non-standard as any other browser, they should really include decent debugging tools if they expect anyone to support their platform.
by Rich on 03/08/2006 at 9:55:38 PM UTC
I actually enabled the debug menu via the Terminal. My JavaScript console displays error with the line number visible and when you double-click on the error it will launch the js file in source view and hightlight the line that is giving the error.
by Jonathan on 09/11/2006 at 9:15:44 AM UTC
I got NULL value error, and there is line number. It is really hard to debug in the case. I have been using Safari Enhancer
by Charlie on 04/22/2007 at 4:57:28 PM UTC
I also got a NULL value, only in Safari.
It came from an Ajax empty xml tag.
The value should be an empty string, not a null value...
by davide on 11/03/2008 at 6:17:55 PM UTC
I HAVE THE PROBLEM OF HAVING SLOW SCRIPT ON MY IMAC WHEN I USE FACEBOOK. THEN I TRIED DOING ALL THINGS TO FIX IT. THEN I FOUND THAT YOU CAN FIX IT DOING WITH THE JAVASCRIPT EXCEPTION THING. BUT WHEN I COPY AND PASTE
defaults write com.apple.Safari IncludeDebugMenu 1
THOSE THINGS IN MY TERMINAL IT DOESN'T WORK THEN THE DEBUG MENU DOESN'T OPENS. I DON'T KNOW WHT TO DO.. HELP PLZ.. I WILL GET IN TROUBLE.. PLZZZZ
by dawa on 04/03/2010 at 8:21:47 PM UTC