Firefox 5 和 Chrome 是否有解决方法“setInterval()”?和“setTimeout()”在非活动选项卡中
JavaScript 优化会导致 Firefox 5 和 Chrome 中的非活动选项卡减慢 setInterval()
和 setTimeout()` 的速度。我将其设置为 66 毫秒,但当选项卡处于非活动状态时,它会上升到 1,000 毫秒。
有没有办法确定选项卡处于非活动状态时经过了多长时间?我需要 JavaScript 来继续运行和执行操作,例如为某些事件播放声音。
有什么办法可以实现这一点吗?
There is a JavaScript optimization that causes inactive tabs to slow down setInterval()
and setTimeout()` in Firefox 5 and Chrome. I have it set for 66 miliseconds but it goes up to 1,000 when a tab is inactive.
There is way to determine how much time passed when the tab was inactive? I need JavaScript to keep running and performing actions, like playing sounds for some events.
Is there any way to achive that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这些限制的全部目的是防止后台页面使用过多的 CPU。即使用户看不到选项卡,您到底在 15Hz 中发生了哪些需要播放声音的事件?
The whole point of those clamps is to keep background pages from using too much CPU. What events, exactly do you have going on in 15Hz that need to play sounds even though the user can't see the tab?
Mozilla 正在研究一种不同的方法来实现 setInterval 和 setTimeout,称为 requestAnimationFrame,也许它可以帮助您解决问题,或者至少希望未来的更新能够解决该问题。
请注意,这是一项实验性功能,在寻求跨浏览器支持时请注意限制。
https://developer.mozilla.org/en/DOM/window.mozRequestAnimationFrame
Mozilla is working on a different way of implementing setInterval and setTimeout, called requestAnimationFrame, perhaps it could help you solve your problem, or atleast hope for future updates that will take care of the problem.
Note that it is an experimental feature, beware of limitations when seeking cross-browser support.
https://developer.mozilla.org/en/DOM/window.mozRequestAnimationFrame