Skip to content

Commit 891312a

Browse files
authored
🐛 [Frontend] Fix: Unique session id (#6335)
1 parent a3b8340 commit 891312a

File tree

1 file changed

+23
-4
lines changed
  • services/static-webserver/client/source/class/osparc/utils

1 file changed

+23
-4
lines changed

services/static-webserver/client/source/class/osparc/utils/Utils.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -992,11 +992,30 @@ qx.Class.define("osparc.utils.Utils", {
992992
}
993993
},
994994

995+
// Function that creates a unique tabId even for duplicated tabs
995996
getClientSessionID: function() {
996-
// https://stackoverflow.com/questions/11896160/any-way-to-identify-browser-tab-in-javascript
997-
const clientSessionID = sessionStorage.getItem("clientsessionid") ? sessionStorage.getItem("clientsessionid") : osparc.utils.Utils.uuidV4();
998-
sessionStorage.setItem("clientsessionid", clientSessionID);
999-
return clientSessionID;
997+
const getUniqueSessionId = () => {
998+
const uuid = osparc.utils.Utils.uuidV4();
999+
// Set window.name. This property is persistent on window reloads, but it doesn't get copied in a duplicated tab
1000+
window.name = uuid;
1001+
sessionStorage.setItem("clientsessionid", uuid);
1002+
return uuid;
1003+
};
1004+
1005+
let uniqueSessionId = sessionStorage.getItem("clientsessionid");
1006+
if (uniqueSessionId) {
1007+
// Check if the tab was duplicated
1008+
// window.name is one of the few things it doesn't get copied, but persists on window reload
1009+
if (window.name !== uniqueSessionId) {
1010+
// Tab has been duplicated, generate a new uniqueId for the duplicated tab
1011+
uniqueSessionId = getUniqueSessionId();
1012+
}
1013+
} else {
1014+
// If no tabId exists in sessionStorage, generate one
1015+
uniqueSessionId = getUniqueSessionId();
1016+
}
1017+
1018+
return uniqueSessionId;
10001019
},
10011020

10021021
getFreeDistanceToWindowEdges: function(layoutItem) {

0 commit comments

Comments
 (0)