electron: getDisplayMedia with Chrome 72 throwing Not Allowed
- Output of
node_modules/.bin/electron --version: v5.0.0-nightly.20190107 - Operating System (Platform and Version): macOS Mojave 10.14.2 (18C54)
- Output of
node_modules/.bin/electron --versionon last known working Electron version (if applicable): never
Expected Behavior Using navigator.mediaDevices.getDisplayMedia({ video: true }), a native screen picker should appear.
Actual behavior The following error is thrown: NotAllowedError: Permission denied
Screenshots
Expected dialog

About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 18
- Comments: 33 (11 by maintainers)
I was able to polyfill getDisplayMedia using the desktopCapturer so that I can use the same code in Electron and the Chrome browser. I’ve only tested it in Windows 10. If it’s handy I can wrap it in a npm package with some options to make the implementation easier.
Adding the polyfill to a BrowserWindow
If you want to add the polyfill to a BrowserWindow with an external website or file in it you need to preload it in the session to make it available to the website. You also need to give the BrowserWindow the permission to use the screen. We just allow everything to make it easier by implementing both setPermissionCheckHandler and setPermissionRequestHandler in it’s basic form.
main.js
The polyfill
The polyfill overrides the native mediaDevices.getDisplayMedia implementation. The getDisplayMedia override gets the sources from the desktopCapturer and displays them in a list in the body tag. (You can use the <style> tag at the bottom of this post to style it like an overlay.) The user can click on a source and then the getDisplayMedia promise resolves the source.
preload-get-display-media-polyfill.js
Some basic styling for the source selection overlay
If you want to quickly test the polyfill here is some basic styling for the selection overlay. But of course you can customize this in any direction. You can add the style tag to the innerHTML of the selectionElem object in the polyfill.
Has anyone successfully used the polyfill mentioned above with
contextIsolationenabled? I don’t think this is possible because you have to pass it through thecontextBridgewhich doesn’t seem to be allowing the stream through. Does anyone have a workaround for this?@WesselKroos I think you should wrap it in an npm package.
Folks, stop asking. See https://github.com/electron/electron/issues/16513#issuecomment-557434953
Is there any update for this? Would be great to be able to use the new WebRTC API for screensharing.
There is no chance this is supported on Electron unless either of these is met:
getDisplayMediaso the source ID can be passedChrome has no intention to deprecate using
getUserMediafor desktop capture (all you can do now on Electron) in the near future.Solution:
https://electronjs.org/docs/api/desktop-capturer https://qiita.com/gtk2k/items/ac08ddeeaf74f3126f81
FYI even with 5.0.0-beta.3 which includes the fix this is still not working throwing NotAllowedError: Permission denied.
For a noob like me, how do I make those changes that @WesselKroos sugests?
ty
@WesselKroos kudos. I had to butcher your code to inject it into 3rd party iframe… but I got it working. Cheers.
@brenca ☝️
@WesselKroos
Awesome! Thanks so much.
No.
Any update ? It’s good if electron support standard WebRTC API.
Any updates on this? Thanks!