question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

support for Page Visibility API aka window blur/focus aka "I leave a tab in background"

See original GitHub issue

I think this library would be great if it would also provide the “onLeave” behavior when the document becomes “invisible”, for instance you changed the tab on your browser, or you minimized the window and call back the “onEnter” when it comes back to visibility. there seems to be an API for that https://www.w3.org/TR/page-visibility/ but i’m pretty sure a way to detect that existed for a lot of time, back in the days i remember using jQuery(window).blur(fn) and focus(fn) a lot for this… it is really useful if you don’t want to leave tab running animation in background. even tho, nowadays, browser should schedule less timer events/animation frames when in background it’s still some useless interval/animations calls that can potentially be saved with this.

I imagine this can be an opt-in behavior because maybe this does not make sense for all usages of Waypoint, but I still think it should be part of the library for a unified way to handle onEnter/onLeave logics.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
levibuzoliccommented, Jul 17, 2017

@jmeas that sounds absolutely fair, while there’s overlap in use, it’s definitely a bit outside the scope of this library. Thanks for taking the time. 👍

1reaction
levibuzoliccommented, Jul 14, 2017

This is also a feature that I’d find useful, in my case I’m using react-waypoint to start/stop/replay some animations that occur as you scroll through different parts of a site. I’ve implemented my own window focus tracking to handle this, but it’d be convenient if react-waypoint had this feature.

I can see how this feature is a little unrelated to react-waypoint but there certainly is some overlap in use cases.

Potentially it could be opt-in via a prop like trackWindowFocus.

Anyway, thanks for a great library. 👌

Read more comments on GitHub >

github_iconTop Results From Across the Web

support for Page Visibility API aka window blur/focus ... - GitHub
blur(fn) and focus(fn) a lot for this.. it is really useful if you don't want to leave tab running animation in background. even...
Read more >
Page Visibility API - MDN Web Docs - Mozilla
The page's content is not visible to the user, either due to the document's tab being in the background or part of a...
Read more >
Is there a way to detect if a browser window is not currently ...
See this answer for a cross-browser compatible solution that uses the W3C Page Visibility API, falling back to blur / focus in browsers...
Read more >
Page Lifecycle API - Chrome Developers
# Background. Application lifecycle is a key way that modern operating systems manage resources. On Android, iOS, and recent Windows versions, ...
Read more >
set interval mdn - You.com | The Search Engine You Control
This method returns an interval ID which uniquely identifies the interval, so you can remove it later by calling clearInterval(). var intervalID ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found