Fix/beforeunload recording disconnect#17052
Fix/beforeunload recording disconnect#17052raghuramala54 wants to merge 2 commits intojitsi:masterfrom
Conversation
…dialog When pressing the browser X button during a meeting, conferenceWillLeave was being dispatched immediately inside the beforeunload handler, causing the user to be disconnected even if they clicked Cancel on the browser's confirmation dialog. Move conferenceWillLeave to a separate unload handler which only fires when the user actually confirms leaving the page. Fixes jitsi#16972
|
Hi, thanks for your contribution! |
|
Have you tested this? Make sure there are two participants in the meeting when testing and after clicking cancel there are two participants that stay in the meeting. You can see in the logs. |
|
Hey @raghuramala54 @damencho, I was looking into why the XMPP disconnect is still being triggered by event = beforeunload. |
|
Find the where the dosconnect message is printed add a breakpoint there and you will figure this out. It is not the visitors. |
Not sure what is the logic there and why it was added, it depends on that. |
|
Ok |
|
Hii @damencho ,
After going through the issue comments what I think of the fix needs to be more nuanced:
What do you think on it ? |
That is the disconnect - sending an unavailable stanza.
This is a rejoin, like reloading the page, you disconnect clear the whole UI and join again. |
|
Nice job on the git and github archeology. |
|
Hi @damencho i just tried debugging it and noticed the xmpp disconnect is getting fired even before the pop shows up. and when i checked xmpp.ts file it shows the disconnect is called on beforeunload and unload both. I will change it in lib-jitsi-meet first i guess. |
|
Hi @raghuramala54 and @damencho, I applied the changes from this PR locally and tried to implement the missing fix in
The lib-jitsi-meet fix ( // Only disconnect on unload (user confirmed leaving).
// mod_smacks (XEP-0198) handles ghost participants server-side.
window.addEventListener('unload', handleDisconnect);
// Show confirmation popup on beforeunload only — do NOT disconnect.
if (!this.options.disableBeforeUnloadHandlers) {
window.addEventListener('beforeunload', ev => {
ev.preventDefault();
ev.returnValue = '';
});
}As far as concern about ghost participants, I found I tested both fixes together — the changes from this PR and the lib-jitsi-meet fix. These two changes together make it work correctly. @raghuramala54 I saw you mentioned you'll change it in lib-jitsi-meet — I've already implemented and tested it. I'm happy to open the PR in lib-jitsi-meet if that helps, or you can take it forward. Whatever works best for you. |
That is correct. But today when I leave by closing the tab, I send successfully a presence unavailable and my thumbnail disappears. With these changes and as I read about what can be done during unload and breforeunload my thumbnail will always be there for 60 seconds, which is not desired and is change of behavior we cannot accept. |
|
Hi @damencho, |

Problem
When pressing the browser's X button during a meeting with an active
recording, two things happened incorrectly even if the user clicked Cancel
on the browser's confirmation dialog:
Both happened because
conferenceWillLeaveandstopLocalVideoRecordingwere dispatched synchronously inside
beforeUnloadHandler— before theuser even saw the confirmation popup. Since JavaScript runs the entire
handler to completion before the browser shows the popup, both actions
happened regardless of the user's choice.
Root Cause
The
beforeunloadevent fires and runs the entire handler synchronously.e.preventDefault()only sets a flag telling the browser to show a popupafter the handler finishes — it does not pause execution. So by the time
the user sees the popup, the disconnect and recording stop had already
happened.
Fix
beforeUnloadHandlernow only shows the confirmation popup when arecording is active. It dispatches nothing.
unloadHandlerwhich fires exclusively when the userconfirms leaving. This is where
stopLocalVideoRecordingandconferenceWillLeaveare dispatched.disableBeforeUnloadHandlersistrue(no popup possible), bothactions are still handled inside
beforeUnloadHandlersince cancel isnot possible in that case.
_removeUnloadHandlerto clean up both handlers properly toprevent memory leaks.
Testing
Fixes #16972