Google is exploring the idea of limiting JavaScript timer wake ups in background webpages starting with Chrome 86, which is shipping a new experimental feature behind chrome://flags. This way, Google Chrome will limit Javascript timer wake ups in background webpages to 1 wake up per minute, similar to Safari. This feature applies to Google Chrome for Windows, Mac, Linux, Android and Chrome OS.
Throttle Javascript timers in background
Upon using DevTools to inspect the work done by popular websites in the background, developers found that Google Chrome users don’t benefit from the excessive usage of Javascript timers when the webpage is opened in the background.
For example, there is essentially no need to track some things especially when the webpage is backgrounded. For example, checking if the scroll position changed, reporting logs, analyzing interactions with ads. Some of the non-essential JavaScript tasks in the background result in unnecessary battery consumption, something Google is now trying to address.
Google aims to reduce the number of Javascript timer wake ups in tabs in the background and significantly extend your PC’s battery life without breaking the user experience. This will not affect websites or applications that rely on WebSockets or long polls to receive messages or updates, Google has confirmed.
According to a technical document seen by TheWindowsClub, Google recently experimented with a prototype that limits Javascript timer wake ups to 1 per minute. In this experiment, Google opened 36 random tabs in the background while the foreground tab was about:blank. Google performed this experiment twice with and without throttling JavaScript timer wake ups to 1 per minute.
At the end of the experiment, Google found that throttling Javascript timers extends the battery life by almost 2 hours (28 percent) for a user with up to 36 background tabs, and when the foreground tab is about:blank.
Similarly, Google ran another experiment. But this time, instead of a blank tab in the foreground, Google played a YouTube video in fullscreen mode. Google also disabled ‘Energy Saver’ settings to prevent the display from going idle. Furthermore, Google also disabled the ‘Automatically adjust brightness’ option in Display settings.
Google aimed to verify if reducing background activities helps extend battery life even when there is foreground activity. According to Google, throttling Javascript timers increases the battery life by almost 36 minutes (13 percent) for a user who has up to 36 tabs running in the background, in addition to a YouTube video in the foreground.
Google says when a Javascript timer causes a wake-up, all Javascript ready timers can execute, even if they didn’t cause the wake-up. There are a couple of ways Google engineers can go ahead implementing this feature to significantly reduce Chrome’s battery consumption.
If a webpage is in the background for 5 minutes, Chrome plans to align JavaScript timer wake ups with a timeout that is less than or equal to 5 minutes to 1-minute intervals. Similarly, Chrome plans to align JavaScript timer wake ups with a timeout that is greater than 5 minutes to 1-second intervals.
However, an enterprise policy will allow system administrators to disable this feature in Google Chrome. This way, the Chrome enterprise browser won’t possibly cause trouble once the feature is shipped to stable. But Google says the enterprise policy will be retired 1 year after the feature ships to stable.
Chrome will also provide developers with a message in the DevTools console when a Javascript timer is delayed by more than 5 seconds.
How to enable the Chrome Battery Saver flag:
- Open Chrome Canary
- Open chrome://flags
- Locate Throttle Javascript timers in background
- Set the flag to Enable immediately when a tab is hidden using the drop-down menu
- Relaunch Chrome.
Since Microsoft Edge is also a Chromium-based browser, the same feature is also available in it in Edge Canary Build 86.0.569.0 under the following flag:
#intensive-wake-up-throttling
However, there is no indication at the moment when the feature will arrive in the new, Chromium-based Edge web browser Stable version.