At my recent gig, Zingku, I have been doing some heavy duty AJAX. There was one particular bug in Safari that I wanted to share with folks that took a while to figure out.
Our environment uses Tomcat as its servlet engine and only on Safari we would experience these random hangs in some AJAX based requests. These AJAX requests would never leave the browser and were difficult to reproduce. However, they happened often enough to frustrate us. The lack of debugging tools in Safari made things very difficult.
Well, after a weekend of digging into the problem I figured out the magic URL that caused the hangs to occur. Safari would just hang on AJAX URLs that contained the character “;”. The reason it was hard to find was that we do not explicitly generate URLs that contain the “;” character. Tomcat does in the form of a “;JSESSIONID=magic_number” token when it thinks the browser does not have the right session cookie. This is what made it feel random.
The solution was to encode the “;” prior to feeding the URL into the XMLHttpRequest.. Here is how you can do it using a quick localized hack:
url = url.replace( ‘;’, ‘%3B’);
I hope Apple will introduce some better debugging tools for Safari in the future.