From a63066bdc8ae9e6746c3113d06c2ead78f4a4851 Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Wed, 28 Jun 2023 08:33:40 +0200 Subject: [PATCH] fix: make closeOnBeforeunload default to false Silently closing the connection when receiving a "beforeunload" event is problematic, because it is emitted: - when downloading a file from another host Related: https://github.com/socketio/socket.io/issues/4436 - when the user already has a listener for the "beforeunload" event (i.e. "are you sure you want to leave this page?") Related: - https://github.com/socketio/engine.io-client/issues/661 - https://github.com/socketio/engine.io-client/issues/658 - https://github.com/socketio/socket.io/issues/4065 That's why the `closeOnBeforeunload` option will now default to false. --- lib/socket.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/socket.ts b/lib/socket.ts index 5b818e8be..1c387235f 100644 --- a/lib/socket.ts +++ b/lib/socket.ts @@ -170,7 +170,7 @@ export interface SocketOptions { /** * Whether to automatically close the connection whenever the beforeunload event is received. - * @default true + * @default false */ closeOnBeforeunload: boolean; @@ -347,7 +347,7 @@ export class Socket extends Emitter< threshold: 1024, }, transportOptions: {}, - closeOnBeforeunload: true, + closeOnBeforeunload: false, }, opts );