Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent timer from being throttled by Chrome when my webpage in background?

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?

like image 745
WhiteYin Avatar asked Sep 19 '25 12:09

WhiteYin


1 Answers

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.

like image 137
GockOckLock Avatar answered Sep 21 '25 03:09

GockOckLock