fix: window content protection on older Windows versions (#47856)

This commit is contained in:
Shelley Vohr 2025-07-24 21:05:28 +02:00 committed by GitHub
commit 01faaa30ea
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 17 additions and 6 deletions

View file

@ -176,6 +176,11 @@ void ElectronDesktopWindowTreeHostWin::UpdateAllowScreenshots() {
if (allowed == allow_screenshots_)
return;
// On some older Windows versions, setting the display affinity
// to WDA_EXCLUDEFROMCAPTURE won't prevent the window from being
// captured - setting WS_EX_LAYERED mitigates this issue.
if (base::win::GetVersion() < base::win::Version::WIN11_22H2)
native_window_view_->SetLayered();
::SetWindowDisplayAffinity(
GetAcceleratedWidget(),
allow_screenshots_ ? WDA_NONE : WDA_EXCLUDEFROMCAPTURE);