Skip to content

[Bug]: setContentProtection issue after hiding and showing the BrowserWindow #29085

@horymury

Description

@horymury

Preflight Checklist

Electron Version

^12.0.6

What operating system are you using?

Windows

Operating System Version

Windows 10 Version 20H2

What arch are you using?

x64

Last Known Working Electron version

No response

Expected Behavior

Upon setting setContentProtection(true), I expect that this setting should be preserved following a .hide() and .show()/.showInactive() of the BrowserWindow.

Actual Behavior

If setting setContentProtection(true) on the BrowserWindow, which behind the scene uses the SetWindowDisplayAffinity WinAPI call (https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowdisplayaffinity), it sets the window affinity as WDA_EXCLUDEFROMCAPTURE for Windows 10 builds newer or equal to Windows 10 Version 2004, which means that the window is completely invisible in screenshots or any other screen captures. Please see screenshot below with window not showing, so content 'behind' it being fully visible.
image

This works fine up until a browserWindow.hide() is called. After that, regardless of doing browserWindow.show() or browserWindow.showInactive() afterwads, screencapture/screenshots then show the window without content, but just a black background, as if the window affinity changed to WDA_MONITOR. Please see screenshot below with window showing with black content after hide and show commands:
image

Testcase Gist URL

No response

Additional Information

Steps to repro:

I created a small project :
https://github.com/horymury/content-protection
which sets setContentProtection as true, then after 5 seconds it hides the BrowserWindow, and after 8 seconds it shows the BrowserWindow again.

If running Windows 10 Version 2004 or newer, if you do a screenshot in the first 5 seconds, you will see that the BrowserWindow correctly does not show up in the image. After 8 seconds ( after the browser window was hidden and then shown again) if you do a screenshot again, you will see that the BrowserWindow appears but with black content, as in the screenshots I uploaded.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy