Skip to content

Client-side disconnect gets fired when leaving page in Firefox but not in Chrome #3639

@Tilogorn

Description

@Tilogorn

I want to:

  • report a bug
  • request a feature

Current behaviour

The socket.on('disconnect') event on the client-side gets fired, when you leave the page in Firefox. Does not happen in Chrome.

I show an error modal when the socket looses its connection because I assume the server went down (not a rare scenario on an embedded device).

Navigating different pages, each with their own var socket = io(); and socket.on('disconnect') methods leads to unwanted flickering of error modals because the browser assumes for a split second that the server went down until the new page gets loaded.

Steps to reproduce (if the current behaviour is a bug)

See my fiddle fork: https://github.com/Tilogorn/socket.io-fiddle
I just added a second page and a link to it.

Open Chrome and navigate to index.html, open the console, check option "persist logs", then click on the link. Nothing special will appear:

Bildschirmfoto vom 2020-09-01 16-00-19

Now do the same in Firefox. You will see the console.log statement of the disconnect listener.

Bildschirmfoto vom 2020-09-01 15-59-38

Expected behaviour

Silently leaving the page. Or having a possibility to detect that the user and not the server closed the connection so no need to show an error modal. reason is transport close in both ways.

Setup

  • OS: Linux Mint 19.3
  • browser: Firefox 80.0 (observed), Chrome 84 (not observable)
  • socket.io version: [email protected]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions