Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

console.log() doesn't work in Safari 6.0 Web Inspector

console.log('hi');

undefined

Is there any similar implementation in 6.0? or Did I do something wrong?

like image 658
mko Avatar asked Aug 18 '12 03:08

mko


People also ask

How do I view the console log in Safari?

Apple Safari To do that, go into Safari's preferences (Safari Menu > Preferences) and select the Advanced Tab. Once that menu is enabled, you will find the developer console by clicking on Develop > Show Javascript Console. You can also use the shortcut Option + ⌘ + C .


6 Answers

Make sure that you're selecting "All" at the top of your console window. Sometimes it'll automatically switch to only show Errors, Warnings, or Logs. If you select "All", then you should see all your console.log()s!

enter image description here

like image 112
Marquizzo Avatar answered Oct 06 '22 01:10

Marquizzo


I found the problem! Logs don't appear in the interactive console (which is located on the bottom), but in the Current Log window instead! You can access it through Develop > Show Error Console or the rightmost source icon in the Web Inspector.

So strange! Is it that hard to get simple output in the console, like puts and print in Ruby?

like image 36
mko Avatar answered Oct 06 '22 01:10

mko


Not preferred but it works.

console.error(message);

Note: I was running gulp serve -d -w which includes a watch. Even then I couldn't see the messages until I restarted gulp.

like image 23
roasty Avatar answered Oct 06 '22 00:10

roasty


I have to develop "for Safari" as my primary target, but because Chrome and Safari both use WebKit as their engine, they are ALMOST identical in execution (one difference is the Safari parses date strings to Date worse).

So debugging and developing in Chrome is generally good enough as long as you do a final sanity check in Safari before checking in your code.

That being said, I wrote a console wrapper that gives me the ability to call console.log in any browser... if it supports console.log, then it just works... otherwise it logs the message in an array that can be inspected.

//======================================================//
// multi browser compatibility - not all support console
//======================================================//
var dummyConsole = [];
var console = console || {};
if (!console.log) {
    console.log = function (message) {
        dummyConsole.push(message);
    }
}
like image 30
dano Avatar answered Oct 06 '22 02:10

dano


If you are using JQuery what I do is dynamically add an ouput field to the page so I can see JavaScript values. The z-index is to keep it on the top. Style it however you want. I usually add a colored border or bright background color so it is easy to find on screen.

var output= 'hello';
$('body').append("<div style='width:50px;z-index:1000'>" + output + "</div>");
like image 30
mbokil Avatar answered Oct 06 '22 01:10

mbokil


I recently came across this post because I was having a similar issue with Safari 14. I use Grammarly for Safari and it creates another frame where the requests are sent. This may happen with other extensions as well.

Safari should select the correct frame by default, but if it does not then you will not see the console logs. If this is happening, there will be a dropdown at the lower right corner of the console window. If you select the website frame the logs will start appearing.

Image of dropdown

like image 27
Kevin M Avatar answered Oct 06 '22 02:10

Kevin M