views:

1787

answers:

4

I am debugging a Safari-specific javascript issue, and I can't get console.log to output to the error log. This is a documented feature of Safari (I'm using version 4.0.3). These statements in my code just seem to be ignored, however. Any ideas why? I'm not finding leads through Google.

A: 

In Firefox I know that you now need to have the firebug console open for console.* functions to work. Maybe it is the same?

SeanJA
A: 

You could try activating debug mode. I have no idea if this will make any difference, but you can give it a try:

http://www.builderau.com.au/blogs/codemonkeybusiness/viewblogpost.htm?p=339270777

Breton
+1  A: 

Are you using the mac or windows build?

On the windows build I can't use most of the stuff in the "Develop" men, none of the javascript options work for me. I can only use

  • Open page with
  • User Agent
  • Show snipper editor
  • Disable *
Alex
+1  A: 

Thanks to Breton and SeanJA for their suggestions of testing directly in the console and making an example file. After doing this, I realized that console.log was, in fact, working in an isolated environment. This made me realize that it must be something particular to my development environment. Checking around, I found that there was some Javscript being loaded early on, designed to define the console object for non-Firebug-enabled browsers.

if (!("console" in window) || !("firebug" in console))
 {
     var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
     "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];

     window.console = {};
     for (var i = 0; i < names.length; ++i)
         window.console[names[i]] = function() {}
 }

This was apparently written before Safari had implemented a console object for its error window.

I've removed that and now everything works well. Thanks, guys.

Eric Nguyen