Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setContentProtection not working on macOS #19880

Open
3 tasks done
veemex opened this issue Aug 22, 2019 · 87 comments
Open
3 tasks done

setContentProtection not working on macOS #19880

veemex opened this issue Aug 22, 2019 · 87 comments

Comments

@veemex
Copy link

veemex commented Aug 22, 2019

Preflight Checklist

  • I have read the Contributing Guidelines for this project.
  • I agree to follow the Code of Conduct that this project adheres to.
  • 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.

@sofianguy
Copy link
Contributor

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.

@veemex
Copy link
Author

veemex commented Aug 29, 2019

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

@veemex
Copy link
Author

veemex commented Aug 29, 2019

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

@sofianguy sofianguy removed the blocked/need-info ❌ Cannot proceed without more information label Aug 30, 2019
@loc
Copy link
Contributor

loc commented Sep 6, 2019

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 😕

@akkhilaysh
Copy link

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

@sofianguy sofianguy added the 7-1-x label Nov 6, 2019
@veemex
Copy link
Author

veemex commented Jan 13, 2020

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 !

@sofianguy sofianguy added 6-1-x and removed 6-0-x labels Feb 19, 2020
@sajjanbalar
Copy link

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
Copy link

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?

@CapOM
Copy link
Contributor

CapOM commented Apr 23, 2020

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

@sajjanbalar
Copy link

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?

@CapOM
Copy link
Contributor

CapOM commented Apr 24, 2020

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

@sajjanbalar
Copy link

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.

@CapOM
Copy link
Contributor

CapOM commented Apr 24, 2020

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

@sajjanbalar
Copy link

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.

@CapOM
Copy link
Contributor

CapOM commented Apr 24, 2020

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)

@sajjanbalar
Copy link

sajjanbalar commented Apr 24, 2020

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?

@CapOM
Copy link
Contributor

CapOM commented Apr 24, 2020

@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

@sajjanbalar
Copy link

@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?

@oalfroukh
Copy link

That's one of the reasons ScreenCaptureKitMac isn't enabled by default yet 😅 still some bugs to work through

OK, thanks, So we will wait to enable it by default to avoid all the side effects 😁

@mtshv
Copy link

mtshv commented Jul 26, 2023

Hello Electron team,
This issue is impacting our project as we rely on this function for our application.

Could you kindly provide us with any updates on this issue and possibly a timeline for resolution? This would be greatly beneficial in helping us manage our project's timeline and expectations.

Thank you for your time and consideration :)

@flyyuan
Copy link

flyyuan commented Aug 19, 2023

The setContentProtection API is based on the NSWindow's sharingType on MacOS.
It doesn't work because NSWindowSharingNone only works on a single window, not on a screen.
I think we need a new API to protect content during screen sharing? The API overflows or hides some content.

@cgri1
Copy link

cgri1 commented Aug 24, 2023

Is there any progress on this problem?

@padmakant-baloji
Copy link

Is there any workaround for this problem?

d3473r pushed a commit to d3473r/jitsi-meet-electron that referenced this issue Sep 1, 2023
In electron utils 2.0.15 we mark them as protected content, but on macOS
WebRTC uses a low level API which sidesteps that. An extra command line
argument is passed to fix that.

See: electron/electron#19880
d3473r pushed a commit to d3473r/jitsi-meet-electron that referenced this issue Sep 1, 2023
This fixes the AoT and screensharing tracker from being captured based on electron/electron#19880
@foxxy432
Copy link

foxxy432 commented Sep 5, 2023

It is ignored by Microsoft because of incompatibilities BUT you can use my fork: https://github.com/lnxx-kernel/electron_touch

@cgri1
Copy link

cgri1 commented Oct 5, 2023

Is there any progress on this problem?

@derekcicerone
Copy link

derekcicerone commented Oct 5, 2023

We were able to get this working if:

  • setContentProtection(true) is called on a BrowserWindow prior to starting the screen share
  • ScreenCaptureKit is enabled via app.commandLine.appendSwitch("enable-features", "ScreenCaptureKitMac"); (before the app is ready)

ScreenCaptureKit support is still being developed in Chromium so I'd only recommend doing this for Electron v26+.

@padmakant-baloji
Copy link

Hello Electron Team,
This is impacting our electron application
Is there any fix or workaround for this?

@dretax
Copy link

dretax commented Dec 1, 2023

https://bugs.chromium.org/p/chromium/issues/detail?id=1309653
chromium/chromium@843de71

@MarshallOfSound based on these findings, and the versioning checks, It should be safe to enable this feature rn?
Saw the feature was also enabled by default in electron.

@dretax
Copy link

dretax commented Dec 5, 2023

  • ScreenCaptureKitMac

@derekcicerone
I've tried the following things mentioned btw on electron 27 fiddler, but I was unable to get it to work. Am I missing something? (Hence the option was removed from a github commit in chromium, I assume something else needs to be enabled maybe?)

@divyanshunegi
Copy link

divyanshunegi commented Jan 31, 2024

I have made it work with this flag

app.commandLine.appendSwitch('disable-features', 'IOSurfaceCapturer,DesktopCaptureMacV2')

and setContentProtection(true)

BUT make sure you are on electron version 23.3.13 or less, latest version does not work, I am not sure why

@flyyuan
Copy link

flyyuan commented Jan 31, 2024 via email

@saghul
Copy link
Contributor

saghul commented Jan 31, 2024

Electron 20 is EOL, you shouldn't be using that or recommending it to anyone.

@divyanshunegi
Copy link

Electron 20 is EOL, you shouldn't be using that or recommending it to anyone.

@saghul I have been struggling with this issue for couple of days now, our app requires some windows to be ignored when screen recording, and the only solution which worked for me was downgrading electron to 23.3.13 as latest, above this setContentProtection flag does not work. I have posted the solution for someone who might be in similar situation as me, meanwhile looking for solutions to upgrade electron as well.

@phwang4
Copy link

phwang4 commented Feb 2, 2024

app.commandLine.appendSwitch("enable-features", "ScreenCaptureKitMac");
is causing the screen share to not work now for me. Anyone else seeing this?
After a few seconds I get the error
DOMException: Could not start video source

Here is a gist that shows this: https://gist.github.com/phwang4/655231b026fdedac408f430604dee0b8
This is mostly the same as fdlmdark's gist but with that new feature and upgraded to electron 28

If I disable that line the screen share will work again (although setContentProtection still doesn't work)
and like divyanshunegi mentioned, only downgrading to electron 23 makes the flag
app.commandLine.appendSwitch('disable-features', 'IOSurfaceCapturer,DesktopCaptureMacV2')
actually work.

@KlausMikhaelson
Copy link

Hey @divyanshunegi, I have been trying the same for a while but it's not working for me, like I can still see the app while doing screen share on google meet, anyway you can share a demo project with it implemented ?

@tbridgejc
Copy link

Beginning with macOS 14.4, releasing in the next 30 days, the old CGDisplayStreamCreate methods are resulting in per-session alerts. What is the current plan to support ScreenCaptureKit in its place, @MarshallOfSound ? :)

@ayushete02
Copy link

ScreenCaptureKitMac

@KlausMikhaelson I am facing the same issue, did you found some solution?

@rakhee28
Copy link

rakhee28 commented Apr 19, 2024

any solution for protecting electron app while sharing entire screen on Zoom app for electron version v30.

@Nantris
Copy link
Contributor

Nantris commented Apr 20, 2024

I'm also wondering if this issue has become a lost cause? In which case the docs really need updating. They already acknowledge it doesn't work on Linux and should specify the same for macOS.

@rakhee28
Copy link

rakhee28 commented Apr 24, 2024

I tried some solution which is working intermediately app.commandLine.appendSwitch('disable-features', 'IOSurfaceCapturer,DesktopCaptureMacV2'). @divyanshunegi as you mentioned above, is this solution working for you in zoom entire screen sharing?
I can't say it is very solid and full proof solution, I need help for specifically version v30

@akylkb
Copy link

akylkb commented Apr 26, 2024

Hey, guys! I have come up with one solution for screen recording protection on MacOS. I found that the VTEncoderXPCService process starts when capturing the screen. And I wrote a function that periodically checks the list of processes.

You can check through Electron Fiddle:
https://gist.github.com/8f65a9c7285a9dcbcd1874415bb34d84

I checked on Ventura 13.0 (22A8380) and it works for me.
I will be glad if you share your experience in your version of os (Mojave, Catalina, BigSur, etc)

@imbdb
Copy link

imbdb commented Jul 7, 2024

Is there any solution for this without killing the screenshare process?

Can't we detect screenshare and blur the app? The blur should only be visible in screenshare and user should be able to see the app.

@Nantris
Copy link
Contributor

Nantris commented Aug 6, 2024

Electron team doesn't really seem to care if their promised feature set breaks, as long as it worked once in the past. It's not good.

At least update the docs...

@imbdb
Copy link

imbdb commented Aug 7, 2024

@ansien I tried v24, the bug is still present on MacOS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests