iOS 5 Safari JavaScript execution exceeded timeout

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

iPad 2, iOS 5, Safari

Posted on Oct 24, 2011 9:33 AM

Reply
19 replies

Jan 5, 2012 5:24 PM in response to illvminatvs

illvminatvs wrote:


I find it very add that instead of contributing anything useful to the discussion you find it best to stay on your porch and scream :"just fix your code" (even though there is no place to pinpoint a problem) and "get off my lawn."

Sometimes the problem isn't easy to pinpoint. If you are unwilling to ship the code as is, your only option is to rearchitect it.


You could check the Safari Developer Forums or the Safari iPhone Mailing List. I checked both briefly and found nothing similar. You could also join the paid iOS Developer Program just so you could burn a developer support ticket. This is more than just a bug report. Apple engineers would actually review your code and tell you what improvements you could make to avoid the issue.


If you want a true "get off my lawn" answer, you could try adding window.console.log() messages to pinpoint the cause. You could use the debug jQuery files. You could try to create the error on purpose. If you can reproduce it, even by cheating, that would go a long way towards understanding it. Apple would certainly appreciate such information in a bug report.

Jan 5, 2012 6:44 PM in response to illvminatvs

illvminatvs, I think the guy is baiting us to start a flame war, which is why I have not responded to his previous post. The reason I think that is because he hasn't said anything even remotely useful related to the issue at hand. The best he could do is "suck it up and work around it" sermon, which we've done already. So I think it's time to go silent until someone adds something relevant to the thread.

Jan 6, 2012 6:28 AM in response to Reluctant JavaScripter

Reluctant JavaScripter wrote:


illvminatvs, I think the guy is baiting us to start a flame war, which is why I have not responded to his previous post.

Why would you respond to my posts at all? This isn't your thread. All you have contributed is "me too" replies and misinformation that both I and the original poster have contradicted.


The reason I think that is because he hasn't said anything even remotely useful related to the issue at hand.


I have provided links to other support forums, suggestions on how to get Apple to review the code in question, and tips for debugging the problem. That is what you consider not "remotely useful"? What suggestions would you have me provide for a problem that has been described in no more detail than "Javascript related"?


The best he could do is "suck it up and work around it" sermon, which we've done already.


We? You have evidence that your problem is the same as that of the original poster? I'm sure illvminatvs would like to know what the problem is. I believe that is the whole point of this thread. If the problem were that easy to identify, it could be easily "worked around".


So I think it's time to go silent until someone adds something relevant to the thread.


That's the way to get good value out of a support forum 🙂

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

iOS 5 Safari JavaScript execution exceeded timeout

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.