Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

console.log() statements do not appear in Safari error log

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. Why?

like image 598
Eric Nguyen Avatar asked Oct 14 '22 13:10

Eric Nguyen


2 Answers

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 JavaScript 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.

like image 182
Eric Nguyen Avatar answered Oct 20 '22 17:10

Eric Nguyen


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 *
like image 24
Alex Avatar answered Oct 20 '22 17:10

Alex