Permalink
base repository: socketio/engine.io-client
Failed to load repositories. Confirm that selected base ref is valid, then try again.
base: 5.0.1
Choose a base ref
...
head repository: socketio/engine.io-client
Failed to load repositories. Confirm that selected head ref is valid, then try again.
compare: 5.1.0
Choose a head ref
  • 3 commits
  • 11 files changed
  • 1 contributor

Commits on May 4, 2021

  1. feat: add the "closeOnBeforeunload" option

    Since [1], the socket is now closed when receiving the "beforeunload"
    event in the browser.
    
    This change was meant to fix a discrepancy between Chrome and Firefox
    when the user reloads/closes a browser tab: Firefox would close the
    connection (and emit a "disconnect" event, at the Socket.IO level), but
    not Chrome (see [2]).
    
    But it also closes the connection when there is another "beforeunload"
    handler, for example when the user is prompted "are you sure you want
    to leave this page?".
    
    Note: calling "stopImmediatePropagation()" was a possible workaround:
    
    ```js
    window.addEventListener('beforeunload', (event) => {
      event.preventDefault();
      event.stopImmediatePropagation();
      event.returnValue = 'are you sure you want to leave this page?';
    });
    ```
    
    This commit adds a "closeOnBeforeunload" option, which controls whether
    a handler is registered for the "beforeunload" event.
    
    Syntax:
    
    ```js
    const socket = require('engine.io-client')('ws://localhost', {
      closeOnBeforeunload: false // defaults to true
    });
    ```
    
    [1]: ed48b5d
    [2]: socketio/socket.io#3639
    
    Related:
    
    - #661
    - #658
    - socketio/socket.io-client#1451
    
    Reference: https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event
    @darrachequesne
    darrachequesne committedMay 4, 2021
    Configuration menu
    Copy the full SHA
    dcb85e9View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    c46611cView commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    0acbe5fView commit details
    Browse the repository at this point in the history
Loading