打开Safari的Javascript调试功能

众所周知,Firefox有一个Error Console可以很方便的调试Javascript的错误,特别加上一些强大的扩展,比如Firebug,在Firefox下面写Javascript简直就是一种享受,最近写一个Mini Editor的时候,在Safari下面一直不太正常,Safari其实也有DEBUG功能的,只是默认没有开启而已,好了,我们的目标就是开启Safari 的DEBUG功能,一共有两种方法:

1 打开C:\Documents and Settings\Your Username\Application Data\Apple Computer\Safari\Preferences.plist文件,他是个XML文件,我们只需要在最末尾的 </dict>
</plist> 的前面增加下面的内容就可以了。

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

2  在Safari.exe 后面增加一个参数/enableDebugMenu就可以了。至于OS/X系统那就更简单了,直接在命令行下运行defaults write com.apple.Safari IncludeDebugMenu 1,就可以搞定了

 

Safari 3 for Windows: Enable JavaScript Debugging

 

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?(找不到run-drosera.cmd,不能运行)

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.

http://pietschsoft.com/post/2007/12/Safari-3-for-Windows-Enable-JavaScript-Debugging.aspx

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!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


kindeditor4.x代码高亮功能默认使用的是prettify插件,prettify是Google提供的一款源代码语法高亮着色器,它提供一种简单的形式来着色HTML页面上的程序代码,实现方式如下: 首先在编辑器里面插入javascript代码: 确定后会在编辑器插入这样的代码: <pre
这一篇我将介绍如何让kindeditor4.x整合SyntaxHighlighter代码高亮,因为SyntaxHighlighter的应用非常广泛,所以将kindeditor默认的prettify替换为SyntaxHighlighter代码高亮插件 上一篇“让kindeditor显示高亮代码”中已经
js如何实现弹出form提交表单?(图文+视频)
js怎么获取复选框选中的值
js如何实现倒计时跳转页面
如何用js控制图片放大缩小
JS怎么获取当前时间戳
JS如何判断对象是否为数组
JS怎么获取图片当前宽高
JS对象如何转为json格式字符串
JS怎么获取图片原始宽高
怎么在click事件中调用多个js函数
js如何往数组中添加新元素
js如何拆分字符串
JS怎么对数组内元素进行求和
JS如何判断屏幕大小
js怎么解析json数据
js如何实时获取浏览器窗口大小
原生JS实现别踩白块小游戏(五)
原生JS实现别踩白块小游戏(一)