0

I noticed the following in Chrome, and I confirmed that Mozilla acts the same way. On my web page I have a simple setTimeout which modifies some child nodes within a DOM tree. When I switch to another tab, and then later go back to the previous tab with my web page I notice in the console that the setTimeout is causing uncaught DOM exception errors. The setTimeout does continue working normally. To me it seems like the setTimeout continues running even when the tab is not active, but the DOM is empty, and it cannot find what it is looking for. I am wondering if any of you have experienced this, and why is this happening? Is there a way to pause the setTimeout when the tab is not active?

bihkorg
  • 1
  • 1
  • Take extra care when using time functions in the browser, you should always clear the timeout to prevent memory leak. Also make sure the element(s) exist before applying the timeout – Qiniso Nov 06 '19 at 19:32
  • Qiniso I am clearing the timeouts to prevent memory leak and making sure the elements exist before applying them. This is not the issue that I am having. The issue I have occurs when I switch to another tab for a few seconds, and then I switch back to the tab with my timeout. It is then that I see uncaught DOM exception errors in the console. To put it in a short sentence, the error occurs only when the tab is inactive. – bihkorg Nov 06 '19 at 21:29
  • Take a look at the tab switching event [here](https://stackoverflow.com/questions/28993157/visibilitychange-event-is-not-triggered-when-switching-program-window-with-altt), maybe this will help. – Qiniso Nov 07 '19 at 12:50

0 Answers0