Visibility.js is a lightweight JavaScript library providing a robust wrapper around the native Page Visibility API, abstracting away vendor prefixes and offering enhanced utility functions. The current stable version is 2.0.2, with recent updates focusing on modernizing its distribution (removing support for legacy package managers in 2.0.0) and improving TypeScript definitions. Its core strength lies in intelligent timers and event handlers: `Visibility.every` creates timers that automatically pause or adjust intervals when a page is hidden, optimizing resource usage, while `onVisible` and `onHidden` provide direct callbacks for state changes. A key differentiator is its built-in fallback for older browsers, although this feature has a known limitation when a browser window loses focus but remains visible.
npm install visibilityjsVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to use `Visibility.every` for interval-based tasks, `Visibility.stop` to clear timers, and `Visibility.onVisible`/`onHidden` for reacting to page visibility state changes.
Migrate to npm/yarn and use modern JavaScript module imports (ESM). Consider transpilation for older browser environments if not already in place.
Be aware of this edge case when relying on the fallback behavior. This primarily affects very old browsers; modern browsers typically support the native API.
Always use `Visibility.stop(timerId)` to clear timers created by `Visibility.every(interval, callback)`.
Ensure you are using `import Visibility from 'visibilityjs';` at the top of your module file, or that the library's script is properly included in your HTML before its usage.
Use `Visibility.stop(timerId)` to clear timers created by `Visibility.every()`. For example: `const timer = Visibility.every(...); Visibility.stop(timer);`
Ensure `visibilityjs` is installed correctly via npm/yarn (`npm install visibilityjs` or `yarn add visibilityjs`). If issues persist, check your `tsconfig.json` for `moduleResolution` settings.
No dependency data recorded yet.