Is it possible to keep the TiddlyTools countdown timer running while the wiki is minimized?

I’ve been using the countdown timer from @EricShulman’s fantastic suit of timers at https://tiddlytools.com/ as a little pomodoro timer within my wiki.

I’ve noticed that the countdown stops when the browser window is minimised. I’m just wondering if anyone knows of any way I can keep the timer running even when not in view?

To reproduce (tested with Firefox on Windows 11):

Go to the countdown timer and start a timer for say 10 minutes, then minimize the window. Open the window after a minute or so and notice that according to the timer only a few seconds have elapsed.

First, please note that the “timers.html” page you linked is no longer being maintained, and has not been updated since Sept 28, 2022. Since then, all TiddlyTools add-ons (including all the time-related functions) are being provided directly on the https://TiddlyTools.com main page. Thus, for the “Countdown Timer”, you should go to TiddlyTools/Time/CountDown and SampleCountdown.

Now, on to your specific issue:

The CountdownTimer uses a javascript “setInterval()” interrupt-driven function that “ticks” once per second to update the time remaining (see TiddlyTools/Time/Ticker).

I tested your issue on my system (using Chrome), and the timer continues to count down even when the browser window is minimized, so this seems like it may be a Firefox-related issue, perhaps due to Firefox’s “Tab Unloading” feature that automatically “unloads” tabs that you are not actively using (e.g., minimized windows).

See Unload inactive tabs to save system memory in Firefox | Firefox Help for technical details, including instructions for how to disable the Tab Unloading feature.

It might be possible for me to re-write the CountdownTimer code to use a different method for computing the time remaining by storing a “timestamp” when the timer is started, and then subtracting the current timestamp when the “tick” processing is triggered. In this way, while the timer would still “freeze” when the Firefox window is minimized, it would immediately update to the correct time remaining as soon as that window is re-activated.

Unfortunately, I’m currently in the middle of some other project work, so I can’t get to this right away, but I will put it on my list. In the mean time, try experimenting with the “disable Tab Unloading” configuration to see if that helps. If it does, it will at least confirm my hypothesis about what is occurring.

-e

2 Likes

Many browsers or addons allow tabs to be suspended, something you may not want to happen so review search about your settings for your browser, check the addons etc…

Thanks Eric. I actually also see this behaviour in Chrome. This is on Windows 11, though weirdly the timer doesn’t freeze when I test it on Chrome opened in Ubuntu via Windows Subsystem for Linux. I did try disabling Tab Unloading but that didn’t do anything.

This helps! The problem seems to be a result of browsers throttling setTimeout and setInterval under certain conditions. Opening Chrome with --disable-background-timer-throttling solves the problem for me. I assume it wouldn’t be wise to use this flag every time you run Chrome though.

Thanks for pointing that out. I’ve updated the links in my original post in case anyone stumble across it in the future.

Thanks again for these tools, they are super-useful! :slight_smile:

@Sii,

I’ve just re-written TiddlyTools/Time/CountDown as described above. Please test to confirm that it now works successfully in FireFox while the browser window is minimized and then restored (also in Chrome without the --disable-background-timer-throttling flag).

In particular, check to see what happens if the countdown is completed while the browser window is minimized. When the window is restored, the timer message/action should trigger, even if the countdown ended a while ago.

Let me know how it goes…

-e

1 Like