Chrome:超时/间隔暂停在后台标签中? [英] Chrome: timeouts/interval suspended in background tabs?

查看:174
本文介绍了Chrome:超时/间隔暂停在后台标签中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用此测试测试 setTimeout 的准确性。现在我注意到(如预期的那样) setTimeout 不是很准确,但对于大多数设备来说不是非常不准确。现在,如果我在Chrome中运行测试并让它在后台选项卡中运行(所以,切换到另一个选项卡并在那里浏览),返回到测试并检查测试结果(如果测试完成),它们将发生显着变化。它看起来像超时运行慢了很多。测试在FF4或IE9中没有发生。

I was testing the accuracy of setTimeout using this test. Now I noticed that (as expected) setTimeout is not very accurate but for most appliances not dramatically inaccurate. Now if I run the test in in Chrome and let it run in a background tab (so, switching to another tab and browse on there), returning to the test and inspecting te results (if the test finished) they are dramatically changed. It looks like the timeouts have been running a lot slower. Tested in FF4 or IE9 this didn't occur.

所以Chrome看起来像暂停或至少放慢了JavaScript没有关注的执行速度。无法在网络上找到有关该主题的更多信息。这意味着我们不能运行后台任务,例如使用XHR调用和 setInterval 定期检查服务器(我怀疑看到 setInterval ,如果时间和我在一起,我会写一个测试)。

So it looks like Chrome suspends or at least slows down javascript execution in a tab that has no focus. Couldn't find much on the net on the subject. It would mean that we can't run background tasks, like for example checking periodically on a server using XHR calls and setInterval (I suspect to see the same behavior for setInterval, will write a test if time is with me).

有没有人遇到过这个?会有解决这个暂停/减速的方法吗?你会把它称为一个错误,我应该把它归档吗?

Has anyone encountered this? Would there be there a workaround for this suspension/slowing down? Would you call it a bug and should I file it as such?

推荐答案

我最近问到这个问题,这是设计行为。当选项卡处于非活动状态时,每秒最多只能调用一次该功能。这是更改代码

I recently asked about this and it is behaviour by design. When a tab is inactive, only at a maximum of once per second the function is called. Here is the code change.

也许这将有助于:
如何使setInterval在Chrome中的选项卡处于非活动状态时也可以工作?

TL; DR:使用网络工作者

这篇关于Chrome:超时/间隔暂停在后台标签中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆