npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

visibility-state-listener

v2.0.0

Published

Cross-browser document visibility state detection library. Detects if user has switched to another window/tab or not.

Downloads

11

Readme

visibility-state-listener

Cross-browser document visibility state detection library. Detects if user has switched to another window/tab or not.

NPM npm version npm bundle size npm

Install

npm i visibility-state-listener

Import

There are different types of distributions depending on your use case. Essentially, the package can be imported via require:

const kit = require('visibility-state-listener')

or via script tag:

<script src="https://unpkg.com/visibility-state-listener@2/dist/visibility-state-listener.iife.js" crossorigin type="text/javascript"></script>

but there are lots of other options. See distribution report below.

Use

const listener = require('./createVisibilityStateListener')
// if you injected the library with script tag use: window.VisibilityStateListener global

// register listener function
listener.on('update', function(newState) {
  const isWindowVisible = newState == 'visible'
})

// start to listen for visibility changes
listener.start()

It registers appropriate listener functions according to the browser. If you want to remove them call .pause():

// no event will be emitted after calling pause
listener.pause()

Distributions Report

This is an auto-generated report that shows the type, name and size of the bundles available to use individually.

[
  "visibility-state-listener.amd.js (1.88 KB)",
  "visibility-state-listener.amd.polyfilled.js (10.25 KB)",
  "visibility-state-listener.cjs.js (1.87 KB)",
  "visibility-state-listener.cjs.polyfilled.js (10.27 KB)",
  "visibility-state-listener.es.js (1.78 KB)",
  "visibility-state-listener.es.polyfilled.js (10.18 KB)",
  "visibility-state-listener.iife.js (1.89 KB)",
  "visibility-state-listener.iife.polyfilled.js (10.26 KB)",
  "visibility-state-listener.umd.js (2.14 KB)",
  "visibility-state-listener.umd.polyfilled.js (10.51 KB)"
]

Babel Polyfills Report

This is an auto-generated report that shows the pollyfils added by core-js to the pollyfilled distributions based on the targets configuration described below.

// polyfills:
[]
// based on the targets:
{
  "android": "4.4.3",
  "chrome": "49",
  "edge": "18",
  "firefox": "78",
  "ie": "9",
  "ios": "6",
  "opera": "73",
  "safari": "5.1",
  "samsung": "4"
}

Thanks for watching 🐬

ko-fi