What I’m trying to do: I’m using a timer to update a progress bar based on the expected time to complete a cloud process. However, I’ve noticed that as soon as I switch to a different browser tab, the timer stops updating. This affects the user experience because the timer doesn’t reflect the actual elapsed time if the user navigates away. I’m using Chrome Version 131.0.6778.205 (Official Build) (x86_64) on macOS Sequoia 15.1 (24B83).
What I’ve tried and what’s not working: I haven’t found any reference to this in the forum or docs, is there any way to have the timer work in the background?
Code Sample: Here’s a simple form to show what I mean.
class Form1(Form1Template):
def __init__(self, **properties):
# Set Form properties and Data Bindings
self.init_components(**properties)
# Initialize the tick counter and timer
self.tick_count = 0
self.timer_1.interval = 0.0 # Timer initially inactive
def start_timer(self, **event_args):
print("start_timer pressed")
self.tick_count = 0 # Reset tick counter
self.timer_1.interval = 1
def timer_1_tick(self, **event_args):
self.tick_count += 1 # Increment the tick counter
self.label_1.text = f"Tick Count: {self.tick_count}" # Update the label
Clone link:
I have an app that shows the progress with a 3-second timer on a Chrome window (with a single tab) running continuously on one monitor. When I switch to other Chrome windows or tabs, the timer continues to work without issue.
I haven’t tested whether the timer continues working when the tab is hidden rather than just being in a window without focus. Could you confirm if your timer stops updating even when running on a visible tab, while your focus is on another tab in a different window?
It happens any time the tab is out of focus. I recorded an example here:

The timer keeps running on my Chrome on Windows 10.
EDIT
My timers stop ticking only when the screen is locked, or perhaps when some power saving feature kicks in.
I have apps that use a timer to ping the server once every 29 minutes just to keep the session alive, and the session expires only when I leave the computer for long enough.
Thanks for checking, maybe this is a macOS issue…
I’m reasonably sure that different browsers apply different performance optimizations. Moreover, these optimizations are subject to change.
If you’re looking for elapsed time, it might be best to read a clock.
3 Likes
Thanks @p.colbert, that is both helpful and hilariously obvious in retrospect. If you want to know the time, better look at the clock! 
This works:
from ._anvil_designer import Form1Template
from anvil import *
import time
class Form1(Form1Template):
def __init__(self, **properties):
self.init_components(**properties)
self.start_time = None
self.timer_1.interval = 0.0 # Timer initially inactive
def start_timer(self, **event_args):
print("start_timer pressed")
self.start_time = time.time()
self.timer_1.interval = 0.1 # Start ticking every 0.1 seconds
def timer_1_tick(self, **event_args):
elapsed_seconds = time.time() - self.start_time
self.label_1.text = f"Elapsed time: {elapsed_seconds:.1f} s"