Socket
Socket
Sign inDemoInstall

single-tab-lock

Package Overview
Dependencies
0
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    single-tab-lock

An npm package to restrict users from opening multiple tabs of a single website.


Version published
Weekly downloads
6
increased by20%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

single-tab-lock

npm version License: Apache-2.0

An npm package to restrict users from opening multiple tabs of a single website.

Installation

npm install single-tab-lock

Usage

import { preventMultipleTabs } from "single-tab-lock";

// Example usage with default values
preventMultipleTabs();

// Customized usage with options
preventMultipleTabs({
  errorMessage: "Custom error message",
  expiryTime: 2000,
  onMultipleTabsDetected: () => {
    console.log("Multiple tabs detected callback");
    // Additional actions on multiple tabs detected
  },
  config: { updateSpeed: 5 },
});

Options

options (Object, optional)

Options object for customizing the behavior.

{
  // Custom error message to display when multiple tabs are detected. Default is a generic message.
  errorMessage: "Custom error message",

  // The time gap (in milliseconds) that determines the threshold for considering a tab as "offline". Default is 1000 milliseconds.
  expiryTime: 2000,

  // A callback function to be executed when multiple tabs are detected. Default is `default_on_multiple_tabs_detected`.
  onMultipleTabsDetected: () => {
    console.log("Multiple tabs detected callback");
    // Additional actions on multiple tabs detected
  },

  // Configuration object for internal processing.
  config: {
    // The speed of internal updates (frames per second).
    updateSpeed: 5,
  },
}

Notes

  • This package, single-tab-lock, provides a simple mechanism to prevent users from opening your web application in multiple tabs simultaneously.

  • LocalStorage Usage: The package uses localStorage to track the status of the tab. Ensure that your users have localStorage enabled for your domain. Users with disabled localStorage might not experience the intended behavior.

  • Fallback Mechanism: It's recommended to implement a fallback mechanism for scenarios where users have disabled localStorage or are using browsers that do not support it.

  • Customization: The animation section in the code can be customized or disabled based on your specific requirements. Adjust the config object in the function call to control the internal processing speed.

  • Security Considerations: Keep in mind that client-side solutions like this can be manipulated by users. If security is a critical concern, consider combining this approach with server-side validation.


## License

`Apache License Version 2.0, January 2004 (http://www.apache.org/licenses/)`

Keywords

FAQs

Last updated on 26 Feb 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc