Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

215
Vistas
Javascript SetInterval execution delay in while switch browser tab

As part of my react app, I have some setTimeout method to run timer and if that reached zero there is prompt will be pops up, which is working fine as long as the browser in in active state, suppose when we switch between one browser tab to another, I had a issue in delay of execution of this setTimeout intervals, it takes more time to reach zero than the configured one or the initial value that we setting.

Let's say timeoutInterval is 120 seconds as default value, then if we switch another tab this setInterval execution latency issue occured. any solution for this ?

Below is my setInterval method to execute timer.

 const [inactiveTimer, setInactiveTimer] = useState(120);
 useEffect(() => {    
     const inactiveInterval = setInterval(() => {
         if (timeoutInterval > 0) {
             setInactiveTimer(timeoutInterval - 1);
         } else if (timeoutInterval === 0) {
             setShowModal(true);
         }
     }, 1000);
     return () => {
        clearInterval(inactiveInterval);
     };
 }, []);
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

When a tab is not active, the function can be called at a maximum of one per second. One option to solve this is to use Web Workers, because they run in separate process, hence are not slowed down.

Another option to solve this issue you can a hack by playing an ~empty sound which will force the browser to keep the regular performance.

More about this inactivation issue - https://codereview.chromium.org/6577021

Empty sound hack - How to make JavaScript run at normal speed in Chrome even when tab is not active?

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda