iOS 5 Safari JavaScript 执行超时

发布于 2024-12-11 17:58:09 字数 1184 浏览 0 评论 0原文

我正在开发一个移动网络应用程序,该应用程序主要是独立的,仅在必要时才与服务器进行通信。目前,正在使用的库是:

  • jQuery 1.6.4
  • jQuery UI 1.8.3
  • jQTouch 的修改/修补版本

在 iOS 5 发布之前,我们还使用 touchscroll.js,但不再需要它,因为 Safari 现在支持position:fixed和原生滚动。

自从 iOS 5 发布以来,似乎随机地引发了这个异常:

JavaScript: Error undefined JavaScript execution exceeded timeout

一旦引发,运行时间超过非常时间(比如 1ms)的 JS 代码将不会被执行野生动物园。刷新页面、转到新页面或转到新域均无效。任何和所有 JS 代码,即使是简单的代码,

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

在不引发异常的情况下,浏览器都不会执行。解决这个问题的唯一方法是强制终止 Safari 并重新启动它。我想也可以将应用程序中的任何远程“重型”代码包装在 window.setTimeout(..., 1) 中,或者利用 Web Workers 来完成除 UI 更新之外的所有操作,但这似乎不是一个非常好的方法。很好的解决方案,因为应用程序相当大,并且需要大量重写。

以前有人遇到过这个问题吗?你会如何调试这样的东西,因为它不是任何单段代码,似乎会让 Safari 进入这种损坏的状态,而且它似乎是随机发生的?

我试图通过执行以下操作来弄清楚移动 Safari 中 JS 引擎的超时是多少:

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

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

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

不幸的是,这个超时异常似乎不是 JS 异常,因此无法在 try/catch 块中捕获它;但是,最大超时时间似乎在几秒范围内。我们应用程序中的任何代码都不会长时间锁定浏览器/JS 引擎(因为它会提供糟糕的用户体验),而且大多数(如果不是全部)执行时间可能不到 300 毫秒(包括任何“重载”的内容)。

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无人问我粥可暖 2024-12-18 17:58:09

您正在使用 watchPosition 吗?如果是这样,请参阅这个答案:JavaScript执行超出超时

我一直在为此抓狂自 iOS 5 发布以来的问题 - 我感受到你的痛苦!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文