Thoughts on Software Engineering

JSObject.getMember() Hangs in Safari in Mac OS X Unless You Move the Mouse

Last few nights I was debugging very strange bug. Few months ago we shipped Java applet signing Web forms in the client’s Web browser. It was tested under IE 6, IE 7, Firefox 2, Firefox 3, Opera 9 and Safari 3 for Windows. We tested with Java 5 and Java 6 in Windows and Linux environment. We didn’t tested the applet in Mac OS X because we didn’t have Mac machine.

Few days ago our customer reported that the applet does not work in Safari and Firefox in Mac OS X. My nightmare started. First I needed to install and run Mac OS X in a virtual machine. It takes a lot of time, runs very slowly and networking is unstable but this is another story.

I found 2 great bugs when using JSObject to access the Web page DOM from java applet in Firefox 3 on Mac OS X and Safari 3 on Mac OS X.

JSObject.getMember() Always Returns Null in Firefox on Mac OS X

The first problem was with Firefox 3 on Mac OS X. When you call JSObject.getMember() to get some property from an object inside the Web page DOM, it always returns null. This method is not supported in Mac OS X and the only information you can find in Internet is that other developers have the same problem and there is no solution. This bug in not published and there is not fix. It just does not work.

The second bug was even more strange.

JSObject.getMember() Hangs in Safari in Mac OS X Unless You Move the Mouse

Sounds strange but this was the exact behaviour: in Safari 3 in Mac OS X 10.4.2 calling JSObject.getMember() blocks for unlimited time until you move the mouse over the applet. It was very strange. When you move the method call returns with the correct result. If you don’t move the mouse over the applet, it hangs for unlimited time. The first thing I did was to configure the JVM for remote debugging, to compile the applet with debug infor and to attach remote debugger form my desktop machine to debug the applet running inside the virtual machine. The strange behaviour was confirmed. Calls to JSObject.getMember() were henging until you move the mouse. I tried lots of ways to overcome this (e.g. adding synchronization, invoking the operations accessing DOM from the AWT dispatch thread and through the main applet thread). Nothing helped.

I found in Internet that others have the same problem and have partial solution with running seperate thread. When I run separate thread for the job accessing the DOM tree, my problem was solved. Nice workaround and works for all browsers. I added additional code to prevent the job accessing the DOM tree to start several times in parallel. Finally, after few other fixes my applet for signing Web forms runs in Safari under Mac OS X.

For some reason the AWT dispatcher thread is put into sleep by Safari during the calls of JSObject.getMember() and moving the mouse wakes it up to process the mouse events inside the applet and that’s why it behaves strangely. I don’t have complete explaination why seperate thread works differently, but it works. Debugging applets’s threading issues was challengeable task but I hope this to be my last project for developing applets.

Previews (4,598), Views (914), Comments (1)

One Response to “JSObject.getMember() Hangs in Safari in Mac OS X Unless You Move the Mouse”

  1. These scripts were so popular Adobe simply added them to Photoshop feature set.
    Other Photoshop versions will function the exact same way so you don’t have
    to panic. This is a beginning Photoshop tutorial, but even experienced Photoshop scrappers may not know this one.

    Look into my web blog :: photoshop gratuit

RSS feed for comments on this post. TrackBack URL