5

I am working on a mobile web app that is primarily self-contained and communicated with the server only when necessary. Currently, the libraries being used are:

  • jQuery 1.6.4
  • jQuery UI 1.8.3
  • Modified/patched version of jQTouch

Up until the release of iOS 5 we were also using touchscroll.js but it is no longer needed since Safari now supports position: fixed and native scrolling.

Since the release of iOS 5, seemingly at random, this exception is raised:

JavaScript: Error undefined JavaScript execution exceeded timeout

Once it is raised, no JS code that runs for more than a very short period of time (say 1ms) will be executed by Safari. Refreshing the page, going to a new page, or going to a new domain has no effect. Any and all JS code, even something as simple as

for(var i = 0; i < 30; i++) ;

will not be executed by the browser without the exception being raised. The only way around this is to force kill Safari and restart it. I suppose it is also possible to wrap any remotely "heavy duty" code in the application in a window.setTimeout(..., 1) or take advantage of Web Workers for everything but UI updates but that doesn't seem like a very good solution as the application is fairly large and it would require a substantial rewrite.

Has anyone encountered this issue before? How would you go about debugging something like this as it isn't any single piece of code that seems to put Safari into this broken state and it can happen seemingly at random?

I tried to figure out what the timeout of the JS engine is in mobile Safari by doing the following:

var start, end;
start = new Date();

try {
   while(true);
} catch (ex) {
  alert('test');
}

end = new Date();
console.log(Number(end) - Number(start) + 'ms');

Unfortunately it seems this timeout exception isn't a JS exception so it cannot be caught in a try/catch block; however, it appears the max timeout period is in the realm of several seconds. None of the code in our app locks the browser/JS engine for that long (as it would provide a terrible UX) and most if not all of it probably has a sub 300ms execution time (including anything that's "heavy duty").

illvm
  • 1,336
  • 13
  • 28
  • I am having the same issue and not using Interval or WatchPosition - intead I am using Jquery Quicksand Plugin... not quite sure what to do. – Mazatec Dec 02 '11 at 16:47
  • Are you getting your browser to be in a corrupted state or does the execution just time out but scripts still run? I wouldn't use plugins like Quicksand or jQuery UI for mobile development unless those plugins are supporting CSS animations. The software animations are pretty resource heavy and could easily time out on a mobile browser. If you insist on using it I would consider rewriting it to using CSS animations, transforms, and transitions instead of absolute positioning and looping. The CSS approach is hardware accelerated in Safari and has *much* better performance. – illvm Dec 02 '11 at 20:51

1 Answers1

0

Are you using watchPosition? see this answer if so: JavaScript execution exceeded timeout

I've been ripping my hair out over this issue ever since iOS 5 was released - I feel your pain!

Community
  • 1
  • 1
Justin
  • 3,418
  • 3
  • 27
  • 37
  • I am not, but my co-worker was on another page at another domain which is accessed prior to this application. I was, however, using setInterval without clearing the interval in the handler. I changed the code to clear the interval whenever the handler is called and restart the interval and haven't had the issue since. I wonder if the two issues are related. – illvm Oct 25 '11 at 18:33
  • interesting - i use several setIntervals without an issue... i think it has to be some sort of iOS5 mobile safari bug because every other browser i test isn't throwing these errors. glad you found a solution though! – Justin Oct 26 '11 at 19:11