JavaScud | Forum | JIRA | Blog |
  Dashboard > DWR中文文档 > ... > Ajax Documentation > Debugging Safari
  DWR中文文档 Log In View a printable version of the current page.  
  Debugging Safari
Added by 黑灵, last edited by 黑灵 on Sep 25, 2006
Labels: 
(None)

Debugging Safari

Safari's debugging abilities are poor, often a good alternative is to get the site working in Firefox properly first and then fix the remaining bugs in Safari.

Safari does have a "Debug" menu, although it is hidden by default. To display the debug menu, in a terminal window, type:

defaults write com.apple.Safari IncludeDebugMenu 1

When Safari is restarted there should be a new Debug menu which contains a "Log Javascript Exceptions" option which should be turned on. In Safari 1.3 and greater you can then view Javascript messages using the "Show JavaScript Console" option. For versions before 1.3, messages appear in the Console application (/Applications/Utilities/Console).

Safari 1.3 and up supports a nice feature not found in other browsers, the ability to log using window.console.log(). Messages appear in the JavaScript console in a dark green, to distinguish them from JavaScript exceptions.

if (window.console) window.console.log(message);
else alert(message);

Keith Wansbrough pointed out that there is a bug in window.console.log - it invokes a sprintf-like function, so if your message includes a % character it is liable to crash Safari. The crash occurs within _CFStringAppendFormatAndArgumentsAux.

You can see this by visiting a JavaScript URL with content.

window.console.log("%s%s%s");

You may need to strip all % characters before invoking window.console.log to avoid this.

Unfortunately I don't know of any debuggers like Venkman for Safari.

Site running on a free Atlassian Confluence Open Source Project License granted to WebWork China. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.3 Build:#808 May 29, 2007) - Bug/feature request - Contact Administrators