This package allows you to determine if a tab is duplicated.
It does so by merging multiple browser events and getting the intersection of their definitions that falls under the same category as duplication of tabs.
It does not cover 100% of all duplication cases and can deliver false-positives in some edge cases, but it covers most of the normal user flows.
This library depends on strongly on sessionStorage and throws an error if it is not available.
It also depends on the following events being fired in the browser:
document.visibilitychange
document.pagehide
document.pageshow
window.blur
window.focus
The idea is as follows: Every tab that runs your application will get a unique uuid. This will be stored in a TabId instance.
In addition to that a history of tabId's will be stored in the session storage. This history is not exposed via an api and the format might change over time.
npm install --save is-tab-duplicated
or
yarn add is-tab-duplicated
There are three functionalities in this library.
initInstance()
- This needs to be called exactly once per page loadisTabDuplicated()
- This returns true if the tab is duplicatedgetInstance().id
- This returns the unique tabId
This example is in React, but it can be used in any other framework or vanilla javascript.
import TabId from "is-tab-duplicated";
// some code
useEffect(() => {
TabId.initInstance();
if (TabId.isTabDuplicated()) {
console.log('This is a duplicated tab');
}
}, [])
// some code