Not long ago, I began to develop the DuelJS library, which provided a convenient interface for determining the status of the Master (active) or Slave (inactive) tab. However, later I began to receive suggestions for optimizing connections for web sockets. DuelJS approach: if tab is active -> keep connection, if inactive ->
put - is not productive. The TabNinja extension comes to the rescue.

New logic
Understand the old logic easily by looking at the screenshot below:

TabNinja offers new logic over old:
The tab with the logic (the same superMaster) is always the same and always is. It changes only in one case - when you close this tab. In this case, the superMaster status automatically passes to another, oldest tab of the remaining tabs. The problem of redundant connections has been resolved.
')
TabNinja essentially has one simple function:
window.isSuperMaster();
You can also use TabNinja without DuelJS, in this case you should use a file from the repository with the appropriate mark (tabninja.without_duel.min.js)
Overview of the algorithm
The TabNinja algorithm is quite simple and is based on localStorage + sessionStorage.
1. If localStorage is unavailable - all tabs will be superMaster
2. The current tab accesses the crash control variable in sessionStorage
3. If there is no variable, the variable is set and the stack of active tabs is deleted.
4. The current tab accesses the active tabs stack via localStorage
5. If the stack of active tabs is empty - create a stack and put yourself there
6. If someone is already present in the stack of active tabs, then the main one who is first in the stack
7. When closing a tab: pull it off the stack
useful links
-
DuelJS demo without TabNinja-
Demo DuS with TabNinja-
TabNinja demo without DuelJS-
TabNinja repository on GitHub-
DuelJS repository on github-
A brief overview of DuelJS on the site-
DuelJS documentation on readthedocs- The picture is taken from
people.howstuffworks.com/ninja.htmOffer your ideas for improving the DuelJS library here or in issues, thanks.
I almost forgot: carefully see the list of tested browsers in README.md
PS: Now I am working on improving the work of TabNinja in Internet Explorer 11 - sometimes there is inappropriate behavior that destroys the work of tabNinja.