# Openvidu Browser sharing screen causes share screen prompts to pop up twice

**URL:** <https://openvidu.discourse.group/t/openvidu-browser-sharing-screen-causes-share-screen-prompts-to-pop-up-twice/4812>\
**Category:** How to implement?\
**Tags:** v2\
**Created:** [October 3, 2023, 2:30am UTC](https://openvidu.discourse.group/t/openvidu-browser-sharing-screen-causes-share-screen-prompts-to-pop-up-twice/4812 "2023-10-03T02:30:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![owenngimli](https://yyz2.discourse-cdn.com/free1/user_avatar/openvidu.discourse.group/owenngimli/32/2286_2.png) [@owenngimli](https://openvidu.discourse.group/u/owenngimli)\
**Post date:** [October 3, 2023, 2:30am UTC](https://openvidu.discourse.group/t/openvidu-browser-sharing-screen-causes-share-screen-prompts-to-pop-up-twice/4812/1 "2023-10-03T02:30:50Z")

</div>

I was using `openvidu-browser` version 2.22 and the share screen worked fine then. Now I’m upgrading to 2.28, but it causes my share screen prompt to pop up twice and share screen doesn’t work at all for tab share screen. Basically what I do when I click on the share screen button:

```js
const handleShareScreen = () => {
    startWebShareScreen((stream) => {
         dispatch(setSharingScreen(true));
         dispatch(setShareScreenStream(stream));
         dispatch(setPresenterMode(true)); 
    }, dispatchMessageToast)
}

```

And what this `startWebShareScreen` is:

```js
const startWebShareScreen = (callback, dispatchMessageToast) => {
  if (!callback) return;

  navigator.mediaDevices
    .getDisplayMedia({ audio: false })
    .then((stream) => callback(stream))
    .catch((error) => {
      dispatchMessageToast(error);
    });
};

```

So basically I set the `stream` from `getDisplayMedia` to a redux state and then I handle that state with a useEffect:

```js
useEffect(() => {
    if (
        !meetingDetail ||
        !isSharingScreen ||
        !shareScreenStream ||
        !shareScreenOpenvidu ||
        !shareScreenOpenviduSession ||
        shareScreenInMeetingRoom
    ) {
        return
    }

    console.log('SS - Get token')
    dispatch(getShareScreenToken(
        meetingDetail.meetingId,
        (token) => {
            console.log("SS - Connect to openvidu session")

            console.log('SS - New publish', { shareScreenStream })
            const streamTrack = shareScreenStream.getVideoTracks()[0]
            const { width, height } = streamTrack.getSettings()

            streamTrack.contentHint = 'detail'
            streamTrack.addEventListener('ended', () => {
                dispatch(setSharingScreen(false))
                dispatch(setShareScreenStream(null))
                dispatch(setPresenterMode(false))
            })

            const connectionData = JSON.stringify({
                userOrganizationId: currentUser.userOrganizationId,
                fullName: currentUser.fullName,
                image: currentUser.avatar,
                isShareScreen: true
            })

            shareScreenOpenviduSession
                .connect(token, connectionData)
                .then(() => {
                    const newPublisher = shareScreenOpenvidu.initPublisher(undefined, {
                        resolution: `${width}x${height}`,
                        frameRate: 30,
                        insertMode: 'APPEND',
                        mirror: false,
                        videoSource: streamTrack,
                        publishAudio: false,
                        publishVideo: true,
                    });
                    shareScreenOpenviduSession.publish(newPublisher)
                    dispatch(setShareScreenPublisher(newPublisher))
                    dispatch(setShareScreenInMeetingRoom(true))
                })
        }
    ))
}, [
    isSharingScreen,
    shareScreenStream,
    shareScreenInMeetingRoom,
    shareScreenOpenvidu,
    shareScreenOpenviduSession
])

```

But this somehow, causes the prompt to pop up again after selecting a screen I want to share. The second time I choose, then it will work. And that’s the thing, it works, but only on the second time. But note that it doesn’t work for tab sharing. What am I missing here?
