- Notifications
You must be signed in to change notification settings - Fork354
Commitdcb85e9
committed
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 Firefoxwhen the user reloads/closes a browser tab: Firefox would close theconnection (and emit a "disconnect" event, at the Socket.IO level), butnot 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 wantto leave this page?".Note: calling "stopImmediatePropagation()" was a possible workaround:```jswindow.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 whethera handler is registered for the "beforeunload" event.Syntax:```jsconst socket = require('engine.io-client')('ws://localhost', { closeOnBeforeunload: false // defaults to true});```[1]:ed48b5d[2]:socketio/socket.io#3639Related:-#661-#658-socketio/socket.io-client#1451Reference:https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event1 parent9eeed5e commitdcb85e9
2 files changed
+19
-12
lines changedLines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
267 | 267 |
| |
268 | 268 |
| |
269 | 269 |
| |
| 270 | + | |
270 | 271 |
| |
271 | 272 |
| |
272 | 273 |
| |
|
Lines changed: 18 additions & 12 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
70 | 70 |
| |
71 | 71 |
| |
72 | 72 |
| |
73 |
| - | |
| 73 | + | |
| 74 | + | |
74 | 75 |
| |
75 | 76 |
| |
76 | 77 |
| |
| |||
91 | 92 |
| |
92 | 93 |
| |
93 | 94 |
| |
94 |
| - | |
95 |
| - | |
96 |
| - | |
97 |
| - | |
98 |
| - | |
99 |
| - | |
100 |
| - | |
101 |
| - | |
102 |
| - | |
103 |
| - | |
104 |
| - | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
105 | 111 |
| |
106 | 112 |
| |
107 | 113 |
| |
|
0 commit comments
Comments
(0)