Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

closeOnBeforeunload not working properly after upgrading to socketio v4.7.5#5055

Discussion options

With following configuration
this.socket = io({
closeOnBeforeunload: false,
reconnection: true,
reconnectionDelay: 100,
reconnectionDelayMax: 2000,
reconnectionAttempts: Infinity,
transports: ["polling"],
secure: true,
rejectUnauthorized: false,
forceNew: false,
timeout: 6000,
})

when I try to leave the page on Firefox the socket connection is disconnected and if I try to log the reason for disconnection it says "transport error "

You must be logged in to vote

Hi! When settingcloseOnBeforeunload: false, the Socket instance will indeed emit adisconnect event when the user reloads the page on Firefox.

Reference:https://socket.io/docs/v4/client-options/#closeonbeforeunload

Replies: 3 comments 1 reply

Comment options

@darrachequesne can you provide any input here?

You must be logged in to vote
0 replies
Comment options

Hi! When settingcloseOnBeforeunload: false, the Socket instance will indeed emit adisconnect event when the user reloads the page on Firefox.

Reference:https://socket.io/docs/v4/client-options/#closeonbeforeunload

You must be logged in to vote
0 replies
Answer selected bydarrachequesne
Comment options

But if I set it to true is silently closes the transport and I am unable to emit any event.
Basically what I want to do is that on javascript "beforeUnload" event I want to emit a socket event it works fine on chrome and other browsers but on firefox no event is being fired.

You must be logged in to vote
1 reply
@darrachequesne
Comment options

I was not able to reproduce the issue:https://github.com/socketio/socket.io-fiddle/tree/socket.io/discussions/5055

$ node server.jsserver listening at http://localhost:3000connect NyI3hlDYDpKmSbt9AAABreceived 'bye'disconnect NyI3hlDYDpKmSbt9AAAB due to transport closeconnect 38pAi8rwORkfnrbPAAADreceived 'bye'disconnect 38pAi8rwORkfnrbPAAAD due to transport closeconnect jxE3dn1g6Stpb-ZNAAAH

Thebeforeunload handler:

window.addEventListener("beforeunload",()=>{console.log("beforeunload");socket.emit("bye");});

Same behavior on Chromium (v123) and Firefox (v127) on Ubuntu 22.04.

Am I missing something?

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Labels
None yet
2 participants
@sarmad36@darrachequesne

[8]ページ先頭

©2009-2025 Movatter.jp