最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to prevent timer from being throttled by Chrome when my webpage in background? - Stack Overflow

programmeradmin2浏览0评论

Last year, Chrome shipped a feature to increase battery life by limiting JavaScript timer wake ups in background webpages.

setTimeout(()=>{
  console.log('done')
}, 1000)

The code above will print logs after 1 second.But when the webpage is in background, it will print after about 10 seconds. It causes a lot of problems.

So, are there any solutions can prevent Chrome from throttling my timers?

Last year, Chrome shipped a feature to increase battery life by limiting JavaScript timer wake ups in background webpages.

setTimeout(()=>{
  console.log('done')
}, 1000)

The code above will print logs after 1 second.But when the webpage is in background, it will print after about 10 seconds. It causes a lot of problems.

So, are there any solutions can prevent Chrome from throttling my timers?

Share Improve this question edited Jun 15, 2021 at 7:00 WhiteYin asked Jun 15, 2021 at 3:27 WhiteYinWhiteYin 451 silver badge5 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 4

You could try loading the script when the window is active, but if it can't be helped, HackTimer.js is a good workaround using Web Workers.

You cannot changes this for your end-users if you are simply the maintainer of the website.

That said, if you are in control of the browser, there is a flag that disables this feature — which you can use when starting Chrome:

--disable-background-timer-throttling

This was already possible in 2019 and remended by Google for automation tests, see this Pull Request.

发布评论

评论列表(0)

  1. 暂无评论