Debugging javascript in Safari for Windows

2019-04-03 07:39发布

问题:

Is there a way to debug javascript using Safari 3.2 in Windows Vista?

I found a link to a debugger named Drosera but I can't get it to work because the information seams to be outdated.

回答1:

Well, apart from the Error Console that can be opened from the Develop menu (which in turn can be enabled in (Prefences / Advanced / Show Develop menu in menu bar) there aren't many javascript debugging options in Safari AFAIK.

Still, the error console is quite useful as it shows javascript errors and also lets you to execute arbitrary Javascript statements.

Since you are on Windows anyway, you could try using the inbuilt Javascript debugger of Google Chrome, which is a browser very similar to Safari (although the Javascript engine is different).



回答2:

I stumbled across this question via google - although it's rather old, none of the answers are quite right, (due to safari being updated to 5.1 since this question was asked)

Enable the develop menu as DrJokepu mentioned:

Prefences / Advanced / Show Develop menu in menu bar

Now you'll see an option in the page menu to Show Web Inspector, which gives you very similar tools to those found in chrome, (Details here). You can also start debugging javascript directly from the develop menu.



回答3:

Yes you can -> CTRL+ALT+I: link



回答4:

You can use Visual Event script by running the following JS code on Safari:

(function() {var protocol = window.location.protocol === 'file:' ?'http:' : '';var url = protocol+'//www.sprymedia.co.uk/VisualEvent/VisualEvent_Loader.js';if( typeof VisualEvent!='undefined' ) {if ( VisualEvent.instance !== null ) {VisualEvent.close();}else {new VisualEvent();}}else {var n=document.createElement('script');n.setAttribute('language','JavaScript');n.setAttribute('src',url+'?rand='+new Date().getTime());document.body.appendChild(n);}})();

Or drag the Visual Event (included in the above link) on the right to your bookmark bar, then you can trigger it from your bookmark bar on a web-page which uses one of the supported Javascript libraries.

The above methods will view the event handlers which are attached to the document elements.


Another solution for JS debugging is to use Firebug Lite. Here is the HTML example:

<html><header></header>
<script type="text/javascript" src="http://getfirebug.com/firebug-lite.js">{overrideConsole: false, startOpened: true, enableTrace: true}</script>
<body>Example</body>
</html>


回答5:

It is possible to make Drosera go -- IIRC you need to enable the developer menu (through preferences) and set a flag in the safari preferences file.

That said, Drosera was slow (due to the architecture) and perpetually buggy. If you download the nightlies from http://nightly.webkit.org you'll get the updated inspector with an integrated debugger. One that does not (hopefully) suck :D

[Edit: and if you do find any bugs in the debugger (ah, irony :D ) it'd be great if you could file them at http://bugs.webkit.org]