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

回眸只為那壹抹淺笑 提交于 2020-02-03 04:34:09

问题


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)


回答1:


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.



来源:https://stackoverflow.com/questions/58842831/check-if-browser-platform-support-screen-capturing-via-getdisplaymedia

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!