You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
getDisplayMedia with Chrome 72 throwing Not Allowed #16513
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 --version on 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
Reacted by juniiorlima, fatpandaria, Jerry F. Zhang, Alexey Murz Korepov, ruifeng96150, Julien Isorce, Mehul pangtey, babyyaqi, Krishna Penukonda, Tanmay Shetty and 7 more
Using navigator.mediaDevices.getDisplayMedia({ video: true }), a native screen picker should appear.
This behavior isn't expected for Electron's case. If we were to implement the plumbing required for this to work we would implement it similar to select-bluetooth-device where we emit all possible options and then the app is responsible for the "choosing" part, whether that is through a UI or just choosing a specific device by default 🤷♂️
Interesting. I understand the previous perspective on this feature but it is now part of the WebRTC standards and no longer a Chrome-specific capability implemented through extensions. It sounds strange to have an official W3C "stable" API that needs to be rebuilt via private SDKs. Certainly makes sense in the short-term, but I would assume the long-term path should be: the official API works, but developers can build a custom UI instead if they like?
@brenca@sofianguy@codebytere could you reopen and make sure this isn't marked as fixed in the release notes as I just tested again in beta 5 and it is still throwing NotAllowedError: Permission denied. I'm happy to help fix it but I'm not an expert in the native binding behind it
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.
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.
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.
Reacted by Claudio Gonzalez, michael-mml, Cody Herzog, Alexey Murz Korepov, Syed Bilal Ali Tirmizi, Fabian Perez, vdanic, 胡尊杰, Gautam Singh, Martin Zaloudek and 26 more
Reacted by Meirion Hughes, hunter, Stefan Wirth, random-webdeveloper, willks, Jacob Muchow, Rasmus Krämer, Akshat Karani, michael, HoJeong Go and 3 more
Reacted by Muhammad Salar Khan, Fabian Perez, vdanic, Meirion Hughes, hunter, Marc Nuri, Stefan Wirth, random-webdeveloper, willks, Jacob Muchow and 9 more
Reacted by Alexey Murz Korepov, vdanic, hunter, Stefan Wirth, willks, Jacob Muchow, Steve Seguin, Sam Perkins, Rasmus Krämer, Asadullo Ganiev and 4 more
in electron 9.2.0, I'm using desktopCapture.getSource(..) to get desktop source, but when I'm using it on my video conferencing application, the other participent voice is recorded to screen sharing audio too (chrome 84 does not). I'm currently stuck with how can I remove that voices from screen audio stream.
Has anyone successfully used the polyfill mentioned above with contextIsolation enabled? I don't think this is possible because you have to pass it through the contextBridge which doesn't seem to be allowing the stream through. Does anyone have a workaround for this?
Reacted by Leso_KN, xw, Jeremy Spiegel and Monhi
Reacted by John Knott, Jon Skelton, Vijay Aravamudhan, Saúl Ibarra Corretgé, Jeremy Spiegel, Stas Kohut and Ibrahim Irfan
Has anyone successfully used the polyfill mentioned above with contextIsolation enabled? I don't think this is possible because you have to pass it through the contextBridge which doesn't seem to be allowing the stream through. Does anyone have a workaround for this?
hey, regarding contextBridge and not allowing streams, is there any reference in the electron docs about it? I've run into the same problem upon upgrading my electron app and am trying to resolve it.
upd: I managed to solve (bypass?) this issue by not returning a media stream from my render but returning a source id and requesting user media on the web app side instead. Probably it’s the intended behavior right now, dunno, hopefully this info will help someone
Activity
codebytere commentedon Jan 23, 2019
@iclems this is probably related to: #16508
MarshallOfSound commentedon Jan 31, 2019
This behavior isn't expected for Electron's case. If we were to implement the plumbing required for this to work we would implement it similar to
select-bluetooth-devicewhere we emit all possible options and then the app is responsible for the "choosing" part, whether that is through a UI or just choosing a specific device by default 🤷♂️iclems commentedon Jan 31, 2019
Interesting. I understand the previous perspective on this feature but it is now part of the WebRTC standards and no longer a Chrome-specific capability implemented through extensions. It sounds strange to have an official W3C "stable" API that needs to be rebuilt via private SDKs. Certainly makes sense in the short-term, but I would assume the long-term path should be: the official API works, but developers can build a custom UI instead if they like?
iclems commentedon Feb 15, 2019
FYI even with 5.0.0-beta.3 which includes the fix this is still not working throwing NotAllowedError: Permission denied.
codebytere commentedon Feb 15, 2019
@brenca ☝️
iclems commentedon Mar 7, 2019
@brenca @sofianguy @codebytere could you reopen and make sure this isn't marked as fixed in the release notes as I just tested again in beta 5 and it is still throwing NotAllowedError: Permission denied. I'm happy to help fix it but I'm not an expert in the native binding behind it
MarshallOfSound commentedon Mar 7, 2019
Haven't confirmed but re-opening, @brenca can you double check this? Feel free to close again if the fix has indeed been applied successfully
16 remaining items
MurzNN commentedon Mar 15, 2020
So that #16763 PR not fix this issue?
saghul commentedon Mar 15, 2020
No.
WesselKroos commentedon Mar 21, 2020
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.
codyherzog-zz commentedon Apr 2, 2020
@WesselKroos
Awesome! Thanks so much.
MurzNN commentedon Apr 7, 2020
Also here https://github.com/hokein/electron-sample-apps/tree/master/desktop-capture is example of custom screen picker
pawhtiobo commentedon May 25, 2020
For a noob like me, how do I make those changes that @WesselKroos sugests?
ty
CapOM commentedon Jun 8, 2020
I think the issue is that the picker view (screenshot in this issue description) used in the standard w3c getDisplayMedia is implemented in chromium/src/chrome/browser/ui/views
(see https://source.chromium.org/chromium/chromium/src/+/master:chrome/browser/ui/views/desktop_capture/desktop_media_picker_views.h;l=20?q=desktopmediapickerviews&ss=chromium%2Fchromium%2Fsrc&originalUrl=https:%2F%2Fcs.chromium.org%2F ) and anything in chromium/src/chrome is not shipped into electron (except a view bits https://github.com/electron/electron/tree/master/chromium_src/chrome/browser )
MeirionHughes commentedon Jun 30, 2020
@WesselKroos kudos. I had to butcher your code to inject it into 3rd party iframe... but I got it working. Cheers.
mehulpangtey commentedon Jul 28, 2020
@WesselKroos I think you should wrap it in an npm package.
tanphamanhh commentedon Aug 17, 2020
in electron 9.2.0, I'm using
desktopCapture.getSource(..)to get desktop source, but when I'm using it on my video conferencing application, the other participent voice is recorded to screen sharing audio too (chrome 84 does not). I'm currently stuck with how can I remove that voices from screen audio stream.jsheffers commentedon Apr 8, 2021
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?ruolunhui commentedon Apr 1, 2022
diamond-darrell commentedon Jul 24, 2022
hey, regarding contextBridge and not allowing streams, is there any reference in the electron docs about it? I've run into the same problem upon upgrading my electron app and am trying to resolve it.
Following https://www.electronjs.org/docs/latest/api/desktop-capturer I get
TypeError: Failed to set the 'srcObject' property on 'HTMLMediaElement': The provided value is not of type 'MediaStream'.error instead of not allowed, which is something I guessupd: I managed to solve (bypass?) this issue by not returning a media stream from my render but returning a source id and requesting user media on the web app side instead. Probably it’s the intended behavior right now, dunno, hopefully this info will help someone