electron icon indicating copy to clipboard operation
electron copied to clipboard

setContentProtection not working on macOS

Open veemex opened this issue 6 years ago β€’ 87 comments

Preflight Checklist

  • [X] I have read the Contributing Guidelines for this project.
  • [X] I agree to follow the Code of Conduct that this project adheres to.
  • [X] I have searched the issue tracker for an issue that matches the one I want to file, without success.

Issue Details

  • Electron Version: 6.0.x , 7.0.x
  • Operating System:
    • macOS 10.14 , macos 10.15
  • Last Known Working Electron version: *4.x.x

Expected Behavior

The function {browserwindow}.setContentProtection(true) , should make the app unrecordable for "Electron desktopCapturer" module.

Actual Behavior

It does not work .

To Reproduce

Make a simple blank app, setContentProtection of the browserWindow, capture the desktop stream using the desktopCapturer module and show it on a canvas.

veemex avatar Aug 22 '19 07:08 veemex

Thank you for taking the time to report this issue and helping to make Electron better.

Would it be possible for you to fork electron-quick-start for a small app that reproduces the issue by itself?

Standalone test cases make fixing issues go more smoothly: it ensure everyone's looking at the same issue, it removes all unnecessary variables from the equation, and it can also provide the basis for automated regression tests.

sofianguy avatar Aug 27 '19 20:08 sofianguy

@sofianguy , yes i will post shortly the link . Thanks !

veemex avatar Aug 29 '19 10:08 veemex

@sofianguy , here you can see it https://github.com/veemex/electron-quick-start "git clone https://github.com/veemex/electron-quick-start setContentProtectionBug" :)

veemex avatar Aug 29 '19 10:08 veemex

It's not working because WebRTC recently switched to a CGDisplayStream-based capturer, which doesn't respect NSWindowSharingNone. Here's the relevant issue https://bugs.chromium.org/p/webrtc/issues/detail?id=8652

AFAICT the only option is for Electron to expose SetExcludedWindow of the DesktopCapturer instance that WebRTC is holding. We'd also probably want to patch it to allow you to exclude multiple windows. But even if we do that work, Windows still won't work, as the DXGI capturer doesn't support excluded windows πŸ˜•

loc avatar Sep 06 '19 22:09 loc

Can we expand on this? I'm looking for answers to protect my electron app content from screen shares and remote desktop software.

akkhilaysh avatar Oct 24 '19 00:10 akkhilaysh

Is this going to be have any fixes? Also does someone recommend a way to use another capturer for the MacOS or another way of achieving this effect of not showing the app during a screen recording that can be converted to a media-stream ? Thanks !

veemex avatar Jan 13 '20 11:01 veemex

Is there any fix for this now? Google Meets can capture my screen even if the screen protection is set to true. I need to urgently fix this! My electron app is valued only because it can't be seen on screen shares!

sajjanbalar avatar Apr 23 '20 05:04 sajjanbalar

It's not working because WebRTC recently switched to a CGDisplayStream-based capturer, which doesn't respect NSWindowSharingNone. Here's the relevant issue https://bugs.chromium.org/p/webrtc/issues/detail?id=8652

AFAICT the only option is for Electron to expose SetExcludedWindow of the DesktopCapturer instance that WebRTC is holding. We'd also probably want to patch it to allow you to exclude multiple windows. But even if we do that work, Windows still won't work, as the DXGI capturer doesn't support excluded windows πŸ˜•

But since windows has the affinity setting, shouldn't it work with that? Also, what ID do I pass to SetExcudedWindow to fix this?

sajjanbalar avatar Apr 23 '20 06:04 sajjanbalar

On Mac, pass the chromium flag --disable-features=IOSurfaceCapturer ( from the app just add: app.commandLine.appendSwitch('disable-features', 'IOSurfaceCapturer') )

CapOM avatar Apr 23 '20 07:04 CapOM

On Mac, pass the chromium flag --disable-features=IOSurfaceCapturer ( from the app just add: app.commandLine.appendSwitch('disable-features', 'IOSurfaceCapturer') )

And what if I want my window to not be seen by other Screen Recording software? This used to work well with setContentProtection() but now any screenshare from Chrome Mac shows the window. Will this help with that? Or will I have wait for electron to change to setExcludedWindow?

sajjanbalar avatar Apr 24 '20 03:04 sajjanbalar

Yes, to have setContentProtection working again you need to pass the above flag.

CapOM avatar Apr 24 '20 03:04 CapOM

Yes, to have setContentProtection working again you need to pass the above flag.

This doesn't seem to work. On Mac OS, Chrome (Google meets specifically) screen share, my window is exposed.

sajjanbalar avatar Apr 24 '20 05:04 sajjanbalar

Probably Google meets ignores all chromium flags. What I meant has to be set for an electron based application on which you have control on the build, so calling app.commandLine.appendSwitch('disable-features', 'IOSurfaceCapturer') in the main.js for example

CapOM avatar Apr 24 '20 06:04 CapOM

Probably Google meets ignores all chromium flags. What I meant has to be set for an electron based application on which you have control on the build, so calling app.commandLine.appendSwitch('disable-features', 'IOSurfaceCapturer') in the main.js for example

Yeah I did that, didn't help. I need Google Chrome (Google meets screen share etc. i.e. webrtc capturer) to not record my electron app which has sensitive content. I was using setContentProtection() to do that. This works fine with firefox on Mac and any browser on Windows, but the screen capturer in Mac chrome is not respecting setContentProtection, I need a way around that.

sajjanbalar avatar Apr 24 '20 06:04 sajjanbalar

Oh I see you would need to pass --disable-features=IOSurfaceCapturer to Google Chrome but that's not possible. I thought you were capturing the screen with your app (electron's desktopCapturer)

CapOM avatar Apr 24 '20 07:04 CapOM

Oh I see you would need to pass --disable-features=IOSurfaceCapturer to Google Chrome but that's not possible. I thought you were capturing the screen with your app (electron's desktopCapturer)

So, as suggested here : https://bugs.chromium.org/p/webrtc/issues/detail?id=8652#c45 can we use webrtc::DesktopCapturer::SetExcludedWindow instead of relying on NSWindowSharingNone for mac?

sajjanbalar avatar Apr 24 '20 11:04 sajjanbalar

@sajjanbalar there is no solution for what you are trying to do since you do not have control to Google Chrome or Google Meeting. The webrtc::DesktopCapturer::SetExcludedWindow API would to use when you setup the screen capture from your own app. I think you miss interpreted the description on this ticket https://github.com/electron/electron/issues/19880

CapOM avatar Apr 24 '20 16:04 CapOM

@sajjanbalar there is no solution for what you are trying to do since you do not have control to Google Chrome or Google Meeting. The webrtc::DesktopCapturer::SetExcludedWindow API would to use when you setup the screen capture from your own app. I think you miss interpreted the description on this ticket #19880

Oh, but setContentProtection works well in windows, also in Firefox mac. I guess what I am seeking is a way to tell the mac os chrome browser to respect the windows choice to not get captured. No way to do that?

sajjanbalar avatar Apr 24 '20 17:04 sajjanbalar

Seems to be fixed in electron 9.0.0. I think we can close ? Or is someone backporting this ?

veemex avatar May 25 '20 18:05 veemex

I was reading through the.electron 9 changelog. There seems to be no mention of this. Are you sure it is fixed?

On Tue, 26 May, 2020, 12:09 AM veemex, [email protected] wrote:

Seems to be fixed in electron 9.0.0. I think we can close ? Or is someone backporting this ?

β€” You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/electron/electron/issues/19880#issuecomment-633680578, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABUIVCFGYFW5U5ZV7ZSEPMTRTK3MVANCNFSM4IOR547A .

sajjanbalar avatar May 26 '20 02:05 sajjanbalar

I was reading through the.electron 9 changelog. There seems to be no mention of this. Are you sure it is fixed? … On Tue, 26 May, 2020, 12:09 AM veemex, @.***> wrote: Seems to be fixed in electron 9.0.0. I think we can close ? Or is someone backporting this ? β€” You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#19880 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABUIVCFGYFW5U5ZV7ZSEPMTRTK3MVANCNFSM4IOR547A .

Although there is no official statement, I have tested with electron 9, Imac with Catalina installed and it seems to work.

veemex avatar Jun 04 '20 13:06 veemex

@veemex are you sure it's fixed? I've just tried it with 9.1.1 and unless i set app.commandLine.appendSwitch('disable-features', 'IOSurfaceCapturer') it doesn't work (and chrome doesn't respect it either)

timothylui avatar Jul 28 '20 11:07 timothylui

Hey y'all,

I wanted to share that in our testing we setContentProtection works on windows:

As you can see in this video there is no Control Menu where our developer is hovering: https://www.loom.com/share/5d93fe55d8a04e10977017b090ac5a91

on mac it does not work:

As you can see in this video the Control Menu on the left shows up in the recording: https://www.loom.com/share/5a56f3a3672645959e86c4e93b75f429

Would anyone be able to point us in the right direction of how we can contribute to a fix, and possibly backporting it?

Having this working on Mac would have a dramatic impact on the flexiblity of the way we build our recording product at Loom

paulius005 avatar Jul 31 '20 20:07 paulius005

@paulius005 , hello ! Try it on electron 9. I have tried it and it worked for me somehow.

veemex avatar Aug 02 '20 07:08 veemex

I tried it on electron 10 and was able to record the screen with QuickTime on mac. Anyone manage to solve this issue?

ahmetuysal avatar Oct 28 '20 20:10 ahmetuysal

I tried it on electron 10 and was able to record the screen with QuickTime on mac. Anyone manage to solve this issue?

@veemex are you sure it's fixed? I've just tried it with 9.1.1 and unless i set app.commandLine.appendSwitch('disable-features', 'IOSurfaceCapturer') it doesn't work (and chrome doesn't respect it either)

Also, disabling IOSurfaceCapturer does not solve the issue. I was able to record the app with QuickTime on mac using Electron 10 when IOSurfaceCapturer was disabled.

ahmetuysal avatar Oct 30 '20 19:10 ahmetuysal

There is a private API CGSSetWindowCaptureExcludeShape to do that and here is an example of usage: https://github.com/heardrwt/RHAdditions/blob/69bed50e5f70304d3c3cf64e74e2005a8ec525eb/RHAdditions/NSWindow%2BRHPreventCaptureAdditions.m

But I don't think we should use it since it is private API.

zcbenz avatar Dec 10 '20 01:12 zcbenz

I tried it on electron 10 and was able to record the screen with QuickTime on mac. Anyone manage to solve this issue?

I also had this problem. Have you solved it?

aizhimin avatar Jan 13 '21 03:01 aizhimin

The Electron version reported on this issue is no longer supported. See our supported versions documentation.

If this is still reproducible on a supported version, please open a new issue with any other new information that a maintainer should know.

Thank you for taking the time to report this issue and helping to make Electron better! Your help is appreciated.

electron-triage avatar Mar 09 '21 19:03 electron-triage

For my own reference:

https://developer.apple.com/documentation/coregraphics/1455137-cgwindowlistcopywindowinfo https://developer.apple.com/documentation/coregraphics/kcgwindowsharingstate https://source.chromium.org/chromium/chromium/src/+/master:third_party/webrtc/modules/desktop_capture/mac/screen_capturer_mac.mm;l=76

MarshallOfSound avatar Mar 25 '21 08:03 MarshallOfSound