diff --git a/src/components/mini-widgets/MiniVideoRecorder.vue b/src/components/mini-widgets/MiniVideoRecorder.vue index acafe9b8e..820496e2c 100644 --- a/src/components/mini-widgets/MiniVideoRecorder.vue +++ b/src/components/mini-widgets/MiniVideoRecorder.vue @@ -248,6 +248,31 @@ watch(externalStreams, () => { updateCurrentStream(savedStream) } }) + +// Try to prevent user from closing Cockpit when a stream is being recorded +const onBeforeUnloadHandler = (): string => { + const alertMsg = ` + You have a video recording ongoing. + Remember to stop it before closing Cockpit, or the record will be lost. + ` + Swal.fire({ text: alertMsg, icon: 'warning' }) + return 'I hope the user does not clicl on the leave button.' +} + +watch(isRecording, () => { + if (isRecording.value) { + window.onbeforeunload = () => { + const alertMsg = ` + You have a video recording ongoing. + Remember to stop it before closing Cockpit, or the record will be lost. + ` + Swal.fire({ text: alertMsg, icon: 'warning' }) + return 'I hope the user does not clicl on the leave button.' + } + } else { + window.onbeforeunload = null + } +})