K
K
killer1122022-01-27 10:13:51
JavaScript
killer112, 2022-01-27 10:13:51

Why does the websocket in Chrome and Firefox not immediately close when the connection is broken?

Situation: it is necessary to notify the user on the page about the interruption of the Internet connection and ensure the integrity of the data that should have been sent to the websocket at the time of the interruption.
What happens and how to reproduce: after loading the page, js establishes a webosocket connection, turn off wi-fi on the device and catch the connection close event.

const ws = new WebSocket('wss://.......');
ws.onopen = () => { ... };
ws.onclose = () => { console.log('Websocket was closed')};

In Safari, the close event appears within 1 second, in Firefox from 2 to 10 seconds, in Chrome, the connection close event can be waited up to 1 minute.
Question: is it possible to somehow influence the responsiveness of Chrome so that the ws connection is closed immediately? Or is this a feature?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question