Question

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

Was it helpful?

Solution

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!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top