Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Safari multiple tabs by working around a Safari bug. #7316

Merged
merged 1 commit into from Oct 11, 2019

Commits on Oct 10, 2019

  1. 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.
    jasongrout committed Oct 10, 2019
    Copy the full SHA
    8de18f5 View commit details
    Browse the repository at this point in the history