@@ -992,11 +992,30 @@ qx.Class.define("osparc.utils.Utils", {
992
992
}
993
993
} ,
994
994
995
+ // Function that creates a unique tabId even for duplicated tabs
995
996
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 ;
1000
1019
} ,
1001
1020
1002
1021
getFreeDistanceToWindowEdges : function ( layoutItem ) {
0 commit comments