Check and listen to all page visibility changes.
npm install page-activeCheck and listen to all page activity changes. Combines several different methods for detecting activity changes into one to ensure maximum coverage.
The following are covered:
- when the user changes tabs
- when the user user changes applications (alt+tab)
- when the user user minimizes browser
- when the user opens dev tools
- desktop browsers
- mobile browsers
- and more...
Warning: this package sets the following callbacks on the global window object. Do not overwrite them or this package may stop functioning correctly:
- onpageshow
- onpagehide
- onfocus
- onblur
``sh`
npm i page-active
Use listenToPageActivation to setup a page activation listener. You can setup multiple listeners without any issues.
`TypeScript
import {listenToPageActivation} from 'page-active';
listenToPageActivation(
/**
* Pass in true here to fire your callback immediately when it is hooked up so you get anfalse
* initial value.
*
* Pass in to only fire your callback on future changes.`
*/
true,
(isActive) => console.info(isActive),
);
At any time you can also call isPageActive to get the current page activation:
`TypeScript
import {isPageActive} from 'page-active';
console.info(isPageActive());
``