Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if browser/platform support screen capturing via `getDisplayMedia`

We can request a media stream to a screen or windows via navigator.mediaDevices.getDisplayMedia(). However, this immediately prompts the user to decide which kind of capturing to use. I need to check if the browser/platform even support screen capturing.

Of course, it is possible to check for 'getDisplayMedia' in navigator.mediaDevices, but this just tells us if the API is supported by the browser. In particular, on FF and Chrome on Android, the API is defined and I can call getDisplayMedia(), but it always immediately returns a NotAllowedError error (which is to be expected: according to caniuse, the mobile browsers do not yet support getDisplayMedia.)

Next, I tried checking navigator.mediaDevices.getSupportedConstraints(). However, my mobile FF returns the exact same object as my desktop FF. In particular, navigator.mediaDevices.getSupportedConstraints().mediaSource is true in both cases. Finally, the data returned by navigator.mediaDevices.enumerateDevices() does not help me either. I only get a device and group ID which I cannot interpret in any way (right?).

Is it possible to detect whether or not screen capture via getDisplayMedia is supported beforehand?

(Note: this Q&A seems fairly similar, but is about getUserMedia and is already quite old)

like image 379
Lukas Kalbertodt Avatar asked Nov 13 '19 17:11

Lukas Kalbertodt


Video Answer


1 Answers

Unfortunately, there's no direct way to feature-detect whether getDisplayMedia will work on those browsers.

All you can do today is browser-sniff the UA string to detect you're not on mobile, where support is lacking.¹

I've filed an issue on the spec based on your question, to see if getDisplayMedia is better left undefined when unsupported.


1. caniuse claims Opera Mobile has support, but this appears not so when I test it.

like image 61
jib Avatar answered Oct 22 '22 16:10

jib