Developing an Excel Add-in with a Timer that Accounts for Visibility Changes
I am creating an Excel add-in using React and Office.js that tracks the amount of time a user spends working in an Excel sheet. I want the timer to pause when the Excel window is minimized or when the user switches to another window or tab, but it continues to run even when the Excel window is inactive.
Steps to Reproduce:
- Build an Excel add-in with React that includes a timer that increments every second to track the time spent working in Excel.
- Detect when the
document.visibilitychange
event occurs and pause the timer when the window is minimized or when the user switches to another window or tab. - Start the timer, open the add-in in Excel, and then minimize the Excel window or switch to another application/tab.
Expected Behavior:
The timer pauses when the Excel window is minimized or when the user switches to another application or tab, and resumes when Excel regains focus or becomes active again.
Actual Behavior:
The timer continues to run even when the Excel window is minimized or the user switches to another application. The visibilitychange
event does not detect when the Excel window becomes inactive in the add-in context.