Somewhat clueless here. It seems that if I leave the browser window open, eventually my JavaScript seems to break. I am not sure if the browser is “timing out” but it seems to forget what it already knows e.g. my variables etc. After this “time out” happens, when interacting with the DOM again the browser can’t successfully carry out my JavaScript functions correctly or event at all.
Should I add a fake click event? If so, how often? Is there a better solution? Is there a way to identify how long before the fake event should be triggered?
What I don’t like about this fake event trigger is that it depends on the browsers memory and will be constantly running counting down the milliseconds. I don’t like having a settimeout function in place constantly.
Browsers sometimes clear memory after idle time. Have you considered using localStorage or session management to preserve state instead of a fake event?
If it affected the timers then what would a solution be? Settimeout wouldn’t work if the timer itself stopped working when a tab becomes inactive. I couldn’t even trigger a fake event at that point.
Do you know at what point does a browser window becomes inactive? As in how long? Still trying to figure this out.
I am sure, that we are on a complete wrong way here. There is nothing that removes variables or js code from the DOM when the tab is inactive. All my apps are open for hours in a tab and only used on demand a few times e day but they work perfectly.
So there is something different causing the TO issue.
Another option you could try is using in-memory state management with periodic checks for DOM visibility (like document.hidden). If you combine that with restoring state when the user returns focus, it might give you a lighter, cleaner alternative without running timers nonstop.