`PageVisibility` in Viritin – Because polling in the void is just sad

Viritin just got a new helper: PageVisibility.
It wraps the browser’s visibility API but goes one better – it also considers focus, because let’s face it: “not hidden” ≠ “actually in use” (hello, multtasking, I still use IntelliJ instead of just Safari).

:package: Code:
PageVisibility.java on GitHub

:dart: Use cases:

  • Stop mindlessly polling while user’s off admiring cat GIFs in another tab
  • Smarter notifications – configure them not to hide automatically if the page is invisible

:mag: Live demo:
pagevisibility @ dokku

Try it. Abuse it. Let me know how it breaks.

5 Likes

Cool idea! Worked really well in my simple test case using multiple screens :) Sadly it is even detecting when I’m admiring my cat GIFs in another application, no more idle (VISIIBLE_NON_FOCUS)

These are somewhat much the same use cases I solved in Idle add-on: Getting notifications and changing the application behavior when not in active use.

Despite the similarity in use cases, it is technically implemented completely differently (mouse+focus) as the Page Visibility API wasn’t that reliable and didn’t cover all the cases - at least back in those days.