31st August 2007

Javascript not working in Safari? This might help…

If JavaScript has suddenly stopped working – or is working only sporadically – in your Apple Safari browser, even though you have it enabled in your Safari Preferences, I might be able to you……..after spending weeks trying to figure this one out I stumbled across a solution quite by accident.

I have the Debug menu enabled (if you do it appears in your menu bar after the Help menu item, if you don’t have it read on for an explanation of what it is and does below), and had the option to “Log Javascript Exceptions” enabled from the Debug menu. This can be a handy feature if you’re trying to diagnose your own JavaScript, but watch out! If your Log File (the JavaScript Console) gets full it runs out of “memory”, even though you may have plenty of free system memory……..this is what happened to me. Once it’s full and can’t log any more exceptions, JavaScript just stops working.

In order to correct this you need to first turn OFF the option to Log JavaScript Exceptions, then choose to Show [the] JavaScript Console window. Be patient! There could be hundreds of thousands of exceptions to load – I had nearly a million. Yes, that sounds like a huge number. It is. I had turned on Logging many many months ago, and then just forgot about it. You’d be surprised how many sites use JavaScript and that have tiny bugs in their code that cause exceptions – these get logged. The more you surf the web, the more JavaScript exceptions that will get logged.

You’ll notice a small button in the bottom left corner of the JavaScript Console window that says “Clear”. Click on it. You may have to repeat the procedure several times, as the Console will clear what it was able to load from the Log File, and then load up some more. Once your Log File is completely clear you can close the Console, and voila! Safari should now execute JavaScript as it should.

As an alternative you can manually delete entries using a text editor, but you cannot delete the Log File itself. Depending on your versions of Mac OS X and Safari, you might find this log file in different places – I found mine at: Macintosh HD/Library/Logs/Console/501/console.log. If you use a utility such as Cocktail to automatically delete Log Files you should be okay, but be sure to check your log files periodically to be sure they are staying cleaned up.

Once you have your Log File cleaned up, I recommend only using the Log JavaScript Exceptions feature when you need it to debug your own script, then keep it turned off when not in use. And definitely you should routinely clean up the Log File.

If you’re not familiar with the Debug Menu, it’s a hidden feature of Safari that opens up a large number of Advanced User/Developer functions (in addition the the logging already mentioned), such as the ability to change the browser’s User Agent, Showing the DOM Tree and View Tree, opening the current page in one of your other installed browsers, and much more. The Debug Menu is not for casual users, but if you can make use of these features, all it takes is a single command line in Terminal to add the Debug Menu to Safari. First, be SURE Safari is NOT running, then open Terminal and type:

% defaults write com.apple.Safari IncludeDebugMenu 1

That’s all there is. If you ever want it gone, just retype the same line with a 0 in place of the 1.

I hope you’ve found this helpful! Let me know if you’ve come up with a different solution – I’d love to know about it.

Kitten
Share with others:
Please Rate this Post:

2 Responses to “Javascript not working in Safari? This might help…”

  1. On June 16th, 2009,Tiff Says:

    Hi, Tech-Kitten!

    It sounds like I’m running into a similar issue: it seems like certain JavaScript functions don’t work in Safari anymore on my computer. It started when I was still using version 3, and when version 4 came out, I was so excited about upgrading so that maybe this problem would go away, but it didn’t. I know you wrote this article a while back, so the Debug menu seems to now be the Develop menu. I haven’t found what equivalent feature in the Develop menu corresponds with the JavaScript exceptions logging you mentioned back in the Debug menu and was hoping that you might have some insight on this.

    For now, I’ve been forced to run Firefox when I run up against this problem in Safari.

    Thanks!

  2. 1 On August 2nd, 2009,Kitten Says:

    Hi Tiff – this one has been plaguing me too since upgrading….there are some sites for which javascript is not working in Safari…….I get why Apple changed the Debug menu to Develop, but not why they took away some of the options…

    The best I cans seem to do now is when I hit a site with safari where javascript doesn’t work, is to change the User Agent (also in the Develop Menu) to either an older version of Safari, or another Mac browser…..if I have to I’ll change it to emulate a Windows browser….in most cases that does seem to help…

    If you do find a better solution I’d love to hear about it!

Leave a Reply

Add your own comment! Your opinion is as valid as anyone elses, so come on... let me know what you think.

**PLEASE NOTE:  Due to the high amount of comment spam I receive I am currently moderating ALL comments, so please be patient, and I WILL respond.  in addition I use Akismet and other spam-comment blockers.  If your comment does not eventually show up it may be that Akismet has determined that it is spam due to your IP address, your links, or the words you use.   If you're not a spammer, drop me a note via my Contact Form and I'll respond personally.

Your email address will never be displayed. Please use a name/pseudonym so that it is easier to distinguish between different anonymous comments. Thanks for commenting!

 
Search: