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 🙏

© 2026 – Pkg Stats / Ryan Hefner

visit-session-persist

v1.0.0

Published

Visit Session Persist is a lightweight JavaScript library that provides cross-tab session management on the same visit. It uses localStorage combined with a heartbeat mechanism to track active tabs. The library persists session data while at least one tab

Downloads

7

Readme

Visit Session Persist

Visit Session Persist is a lightweight JavaScript library that manages cross-tab session data on the same visit. It uses localStorage combined with a heartbeat mechanism to track active tabs, ensuring that session data persists while at least one tab is open and is automatically cleared when all tabs are closed. This behavior forces re‑authentication on subsequent visits.

The library also handles modern browser background throttling and sleep states by listening for the Page Visibility API as well as experimental freeze/resume events.

Features

  • Cross-Tab Session Persistence:
    Session data is shared across tabs on the same visit.

  • Automatic Session Expiration:
    When the last active tab is closed (or its heartbeat stops), the session data is cleared automatically.

  • Customizable Timing:
    Configure the heartbeat interval and stale threshold to suit your application and browser behavior.

  • Modern Browser Compatibility:
    Uses visibilitychange, and experimental freeze/resume events to keep sessions updated even when tabs are throttled or suspended.

  • Easy Integration:
    Plug directly into your existing state persistence solution (such as Redux Persist, Vuex Persist, or NgRx) with minimal configuration.

Installation

Install via npm:

npm install visit-session-persist

Or via Yarn:

yarn add visit-session-persist

Usage

Basic Integration

Import and create an instance of the storage adapter with custom options if desired:

import { createVisitSessionStorage } from 'visit-session-persist';

// Create an instance with custom options (optional)
const visitSessionStorage = createVisitSessionStorage({
  heartbeatInterval: 3000, // Heartbeat every 3 seconds
  staleThreshold: 7000,    // Mark a tab as stale if no heartbeat in 7 seconds
});

// Use the API directly
visitSessionStorage.setSessionData('user', { name: 'Alice' });
const user = visitSessionStorage.getSessionData('user');
console.log(user);

Integration with State Persistence Libraries

Redux Persist

import { createVisitSessionStorage } from 'visit-session-persist';
import storage from 'redux-persist/lib/storage';

const visitSessionStorage = createVisitSessionStorage();

const persistConfig = {
  key: 'root',
  storage: visitSessionStorage,
  // additional Redux Persist config...
};

// Then pass persistConfig to persistReducer in your Redux store setup.

Vuex Persist

import VuexPersistence from 'vuex-persist';
import { createVisitSessionStorage } from 'visit-session-persist';

const visitSessionStorage = createVisitSessionStorage();

const vuexLocal = new VuexPersistence({
  key: 'my-app',
  storage: visitSessionStorage,
});

// Include vuexLocal.plugin in your Vuex store plugins.

API

The library exposes the following methods:

  • setSessionData(key, value):
    Stores a value (JSON-stringified) under the given key.

  • getSessionData(key):
    Retrieves the value stored under the given key.

  • removeSessionData(key):
    Removes the specified key from session storage.

  • clearSession():
    Clears all session data.

In addition, the library automatically handles heartbeat updates and synchronization across tabs.

How It Works

  1. Heartbeat Mechanism:
    Each tab updates its unique heartbeat in localStorage at the configured interval. Tabs that have not updated within the stale threshold are removed from the active tabs list.

  2. Event Listeners for Throttling:

    • visibilitychange: Immediately updates the heartbeat when a tab becomes visible.
    • freeze/resume: Experimental events (supported in some browsers) that trigger updates when a tab is suspended or resumed.
    • pagehide/pageshow: Provide additional hooks for handling cache and suspension scenarios.
  3. Session Cleanup:
    When all tabs are closed (i.e., no active heartbeat remains), the session data is cleared automatically, ensuring a fresh session on the next visit.

Contributing

Contributions are welcome! Please fork this repository, create your feature branch, and submit a pull request. For major changes, please open an issue first to discuss what you would like to change.

License

This project is licensed under the MIT License.