shawnmclean / Idle.js

Javascript activity library for the browser. (away, idle, etc)
Other
402 stars 59 forks source link

Idle.js interprets page navigation in Firefox as being "away" #9

Open chrisbloom7 opened 11 years ago

chrisbloom7 commented 11 years ago

If you go to http://shawnmclean.github.io/Idle.js/ in Firefox and refresh the page, you'll briefly see idle.js report that "User is not looking at page" before the page repaints. This is also happening in a dashboard app that I have whenever a user clicks on any link that takes them away from the dashboard - the "background polling paused" message I have setup is displayed for a second while Firefox is busy loading the new page.

shawnmclean commented 11 years ago

I'll look into it soon.

chrisbloom7 commented 11 years ago

Thanks. Here's a quick work around for anyone that needs it:

// Requires jQuery < 1.9, or https://github.com/gabceb/jquery-browser-plugin

function idlePause() {
  // ...
};

function idleResume() {
  // ...
};

function supportsIdleJs(){
  // See: https://github.com/shawnmclean/Idle.js/issues/7
  return !$.browser.msie || parseInt($.browser.version) > 8;
};

function supportsVisible(){
  // Idle.js interprets page navigation in Firefox as being "away"
  // See: https://github.com/shawnmclean/Idle.js/issues/9
  return supportsIdleJs() && !$.browser.mozilla;
};

var idler = new Idle({
  onAway:      supportsIdleJs()  ? idlePause  : jQuery.noop,
  onAwayBack:  supportsIdleJs()  ? idleResume : jQuery.noop,
  onHidden:    supportsVisible() ? idlePause  : jQuery.noop,
  onVisible:   supportsVisible() ? idleResume : jQuery.noop,
  awayTimeout: 5000,
});