Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Safari multiple tabs by working around a Safari bug.
Fixes jupyterlab#6921 We use local storage events to communicate between browser tabs in order to see if there are any other tabs with a particular workspace name. The standard says that local storage events are only supposed to be triggered by local storage changes from *other* tabs. However, Safari sometimes triggers these events from changes by the current tab. Here is an example illustrating this: ```html <html> <body> <div id='report'>No events received</div> <script> let date = new Date().getTime(); let report = document.getElementById('report'); window.addEventListener('storage', ev => { if (ev.key !== 'SOME KEY') { return; } if (ev.newValue === date.toString()) { report.innerText = `BUG: received my own local storage change (${date}) as an event.`; } else { report.innerText = `Another tab was reloaded with timestamp ${ev.newValue}`; } }); window.localStorage.setItem('SOME KEY', date); </script> </body> </html> ``` Open that page in two different Safari tabs and start refreshing each one alternately. It was pretty easy for me to get one of the tabs to indicate the bug was happening. Things worked fine in firefox and presumably would in Chrome too. A workaround implemented here is to manually ignore local storage events that we triggered. Even if we move to BroadcastChannel (see jupyterlab#7315), we'll still need to deal with this since Safari doesn't implement broadcast channel, so we'd have to fall back to something like local storage on Safari.
- Loading branch information