javascriptgoogle-chromescreensharing

mediaDevices.getDisplayMedia with "window" for displaySurface, streams the whole browser?


I'm using mediaDevices.getDisplayMedia with config

 { audio : false, video : { displaySurface : "window" }}

The Chrome popup appears then I select the tab I want to share but the stream is the entire browser, the displaySurface value seems ignored and fallbacks onto "browser".

I'm using Chrome 112 and I was wondering if this is a known bug, or this is the expected behavior?

Edit: I'm getting the same result from mozilla.org (scroll down to Result to test)


Solution

  • I found the solution so I answer my own question, hoping it helps someone. The key is to set preferCurrentTab and browser instead of window

     { preferCurrentTab: true, audio : false, video : { displaySurface : "browser" }}
    

    in the options for getMediaDisplay and then the tab is already selected and the stream is the window.