Bimal Kafle
Bimal Kafle

Reputation: 27

Is there any way to know that the selected window for screen sharing is closed in firefox browser?

When using the MediaStream API to capture a screen recording in Firefox, it's challenging to detect when the selected window for screen sharing is closed. The MediaStreamTrack object provides several events, such as ended and inactive, but these events are not fired when the user closes the selected window. Note: This issue is specific to Firefox, as Chrome, Safari, and Edge browsers work correctly in this scenario. Following is the code i am using right now:

screenRecordingStream.value =
    await navigator.mediaDevices.getDisplayMedia(
        displayMediaOptions
    );
screenRecordingStream.value.getTracks().forEach((track) => {
    track.addEventListener('ended', () => {
        debugger;
        if (isRecording.value) {
            completionStatus.value = true;
            stopMediaRecorder();
        }
    });
    track.addEventListener('inactive', () => {
        debugger;
        if (isRecording.value) {
            completionStatus.value = true;
            stopMediaRecorder();
        } else {
            changeMode(1);
        }
    });
    track.addEventListener('inactive', () => {
        console.log('Track inactive');
        // ...
    });
    track.addEventListener('mute', () => {
        console.log('Track muted');
    });
    track.addEventListener('unmute', () => {
        console.log('Track unmuted');
    });
    track.addEventListener('overconstrained', () => {
        console.log('Track overconstrained');
    });
    track.addEventListener('readyStateChange', () => {
        console.log('Track ready state changed');
    });
});

I have tried testing it in other browser and it is working as expected. Recording stopped when the selected tab or window is closed. In case of firefox when the selected tab or window is that event is not detected.

Upvotes: 0

Views: 125

Answers (1)

Bimal Kafle
Bimal Kafle

Reputation: 27

I reported this issue on Bugzilla and found out it's a bug. The fix will be in the next Firefox update, version 128.

Upvotes: 2

Related Questions