0

I am trying to build a web app that could capture the user's desktop. I found this web api that should do the job perfectly, but I can't seem to make it work. Right now it should be supported both on the latest version of Edge and on Chrome 70 through enabling a flag, but on both browsers if I am looking at the navigator object the getDisplayMedia() function is not in there. I also tried calling the function, but I get an error saying that it is not a function(which confirms that it is actually not in the navigator). What could be the problem?

Thanks in advance!

edit: Here is my javascript

function na() {
    navigator.mediaDevices.getDisplayMedia({
        video: {
            mandatory: {
                chromeMediaSource: 'desktop',
                minWidth: 1280,
                maxWidth: 1280,
                minHeight: 720,
                maxHeight: 720
            }
        }
    }).then((stream)=>console.log(stream))
    console.log(navigator)

}

na();
jib
  • 40,579
  • 17
  • 100
  • 158
Adrian Pascu
  • 949
  • 5
  • 20
  • 48

1 Answers1

5

While not available yet, getDisplayMedia can be polyfilled. This is described in this blog post. In Chrome this requires an extension so if you start to develop just now it might be better to wait until getDisplayMedia is available in Chrome (it should be in Chrome Canary without flags soon)

Note that you are mixing old constraints (which were required to get desktop sharing from navigator.mediaDevices.getUserMedia in Chrome) with navigator.mediaDevices.getDisplayMedia which is not going to work.

Philipp Hancke
  • 15,855
  • 2
  • 23
  • 31
  • Ok,thanks for your help! I thought those constraints would work since I made it work in an electron app which is chromium after all – Adrian Pascu Nov 25 '18 at 08:26
  • for electron see [this question](https://stackoverflow.com/questions/48685507/webrtc-screensharing-in-electron) which also links to an example. – Philipp Hancke Nov 25 '18 at 15:02