Debugging javascript in Safari for Windows

36,392

Solution 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).

Solution 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.

Solution 3

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

Solution 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>

Solution 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]

Share:
36,392
AntiTcb
Author by

AntiTcb

​Worked in software engineering for the past 16 years, within diverse industries including banking, insurance, and aviation. Has a licentiate degree in Computer Science and Informatics from the New University of Lisbon. Experienced writing all types of programs, both desktop, and web-based applications, from complex three-tiered enterprise applications to simple desktop and web-based applications. Accustomed at modifying existing applications and extending functionality, optimizing and patching up security issues. Loves technology since he was a small kid when he got his first computer, a Commodore 64 with only nine years of age. Since then has programmed and hacked his way through life. Always keen to learn new things, has a good knowledge of various technologies, being able to apply the finest tool for the job, and responsible for ensuring that quality solutions meet business goals.

Updated on August 04, 2020

Comments

  • AntiTcb
    AntiTcb almost 4 years

    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.

  • James Baker
    James Baker over 15 years
    Seconded. Drosera is gone from the nightlies; use the integrated debugger.