ifvisible.js icon indicating copy to clipboard operation
ifvisible.js copied to clipboard

ifvisible.OnEvery doesn't continue after switching tabs

Open khaledosman opened this issue 7 years ago • 4 comments

version: 2.0.10

I have the current code

ifvisible.setIdleDuration(900);

    ifvisible.idle(function() {
        console.log('idle')
        document.body.style.opacity = 0.5;
    });

    ifvisible.wakeup(function() {
        console.log('wakeup')
        document.body.style.opacity = 1;
    });

    // instead of setInterval, this will not call the callback if the user is idle
    ifvisible.onEvery(5, function() {
        console.log('interval');
    });

the interval initially gets called correctly, if I switch tabs then get back to the page "wakeup" is fired however the interval doesn't resume

khaledosman avatar Mar 29 '17 16:03 khaledosman

Any fix or workaround for this problem?

keskistok avatar May 15 '17 08:05 keskistok

@keskistok I rolled back to v1.0.6, seems to work there.

khaledosman avatar May 29 '17 15:05 khaledosman

I'm using v1.0.6 and this issue is still happening for me there. I'll likely have to set a timeout on blur and then clear it on focus like this:

      ifvisible.on('blur', () => {
        let blurredIdleTimeout;
        blurredIdleTimeout = setTimeout(() => {
          // it's idle, perform actions here
        }, MILLISECONDS_TO_IDLE);
      });
      ifvisible.on('focus', () => {
        clearTimeout(blurredIdleTimeout);
      });

bradydowling avatar Feb 28 '19 16:02 bradydowling

I fixed this as of 3.0.1 on my fork https://github.com/rosskevin/ifvisible/releases

rosskevin avatar Jun 18 '22 02:06 rosskevin