single-tab-lock
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";
preventMultipleTabs();
preventMultipleTabs({
errorMessage: "Custom error message",
expiryTime: 2000,
onMultipleTabsDetected: () => {
console.log("Multiple tabs detected callback");
},
config: { updateSpeed: 5 },
});
Options
options
(Object, optional)
Options object for customizing the behavior.
{
errorMessage: "Custom error message",
expiryTime: 2000,
onMultipleTabsDetected: () => {
console.log("Multiple tabs detected callback");
},
config: {
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/)`