Safari 3 for Windows: Enable JavaScript Debugging

21. December 2007

As you probably know, Safari 3 doesn't allow you to turn on the debug menu within any settings dialogs. It also doesn't come with a JavaScript Debugger either. This makes it almost impossible to do any JavaScript development for Safari. Luckily you can turn on the debug menu, and there is a debugger you can download.

Turn on the Debug menu

Step 1: Open up the Preferences.plist file in notepad.

In Windows XP:
C:\Documents and Settings\USERNAME\Application Data\Apple Computer\Safari\Preferences.plist

In Windows Vista:
C:\Users\USERNAME\AppData\Roaming\Apple Computer\Safari\Preferences.plist

Step 2: Add the following to the end of the file, just before "</dict></plist>":

<key>IncludeDebugMenu</key><true/>

Step 3: Now open up Safari and you have the Debug menu

Where can I find a Debugger for Safari?

You can download the Drosera debugger here: http://nightly.webkit.org
Now, before you go trying to run it, you'll want to read the next section below.

How do I run Drosera in Windows?

Step 1: Make sure you download the Webkit Nightly Build located at http://nightly.webkit.org and extract its contents somewhere on your harddrive.

Step 2: If you're running Win Vista then  you'll have to add the following to the WebKitPreferences.plist file, just before "</dict></plist>":

<key>WebKitUserStyleSheetLocationPreferenceKey</key><true/>

You can find the WebKitPreferences.plist file within the same folder that the Preferences.plist file is in; it's path is shown above. Also, if you're running Vista and you don't add this snippet to the WebKitPreferences.plist file, then Safari will crash and you wont be able to debug until you add it.

Step 3: Execute the run-nightly-webkit.cmd file. This will launch Safari.

Step 4: Execute the run-drosera.cmd file. This will launch Drosera.

Step 5: Execute the FindSafari.exe file. This will link up Drosera to your running instance of Safari.

If you have multiple instance you may want to close all but one. I don't know if multiple instances of Safari will cause this to not work, but it's better to be safe.

Step 6: Now you can access web pages with Safari and step through / break on errors in the code.

Additional Links

The WebKit Open Source Project
Safai Developer FAQ - How do I debug JavaScript in Safari?

Additional Comments

I'm not exactly sure why Apple makes us jump through these hoops to be able to debug JavaScript within Safari. It's quite a hassle, and even after all that work I still have the following issues with the experience:

  • Debugging with Drosera is very slow, and actually froze up a couple times on me and I had to restart Safari and Drosera.
  • Since I'm used to the debugging experience in MS Visual Studio, I am very dissapointed in Drosera. You'll know what I mean when you use it.

All in all, I hope this post saves someone the hours it took me to figure this all out. Afterall, there isn't any instructions (at least that I could find) on the WebKit site that tells you how to actually run Drosera on Windows.

Good luck, and I hope Apple improves the developer support for Safari.

General ,



Comments

Feng
Feng
1/11/2008 10:08:00 AM #
Thanks for this. But this still cannot resolve my problem.

Additional steps (beyond yours) are required from my side to make basic thing happen (Drosera able to be launched):

First of all, I have to add the "c:/program files/safari" to the %path% variables. Otherwise the two cmds will crush (because it cannot find dependent dlls).

Second, I cannot use the newest Nightly from the WebKit site. My safari is of version 3.0.4. If I run WebKit-r29336, the dlls don't match and Drosera cannot be launched. I have to use a older version r28890.

Then I do as your instruction. However, Drosera still cannot find the living Safari instance. It's frustrating.

My machine is on Vista. Using Safari 3.0.4.

Thanks!
Sudhakar
Sudhakar
1/28/2008 1:22:00 AM #
Ahh.. In run-drosera.cmd , a space was missing before FindSafari.exe. Now its working for me. Might be of some help 2u.
Chris
Chris
2/12/2008 5:26:00 AM #
Thanks for this. I had spent hours trying to figure out the "instructions" on Apple's website to no avail.
Rush
Rush
3/7/2008 3:02:34 PM #
Hey thanks a lot .. i was really tired finding this stuff .. you have done a great help Smile
Thanks a lot
Megha
Megha
3/7/2008 11:34:11 PM #
I cnt attach my Safari browser with Drosera.....can some one please help with this. I followed all steps mentioned in this thread
Megha
Megha
3/8/2008 12:13:28 AM #
u need to add <key>WebKitUserStyleSheetLocationPreferenceKey</key><true/> to both WebKitPreferences.plist as well as Preferences.plist. also i used the nightly build version 28890. n life is simple for me again Smile
  
11/16/2008 10:25:50 PM #
Pingback from helephant.net

Helephant.com  » Blog Archive   » Debugging pages in Safari
1/21/2009 8:05:26 PM #
Pingback from web-linux.ru

Web and Linux  » Blog Archive   » Отладка JavaScript в Opera, FireFox, IE и Safari
10/20/2009 12:57:01 AM #
Pingback from affordablewebdeveloper.com

Safari 3 for Windows: Enable JavaScript Debugging - Affordable Web Developer - Just another WordPress weblog on Affordable open source web development.
Comments are closed