How to Make an Electron Window Invisible to Screen Capture
By Mit Parikh · May 2025 · 8 min read
The mechanism: SetWindowDisplayAffinity
Windows exposes a function called SetWindowDisplayAffinity that controls whether a window appears in screen captures. When called with the flag WDA_EXCLUDEFROMCAPTURE, the Desktop Window Manager (DWM) renders the window normally on your physical display but omits it from all capture pipelines.
This means the window is invisible to Zoom, Teams, Google Meet, OBS Studio, Windows Game Bar, Loom, ShareX — everything. The exclusion happens at the kernel display subsystem level, not at the application layer. There is no workaround.
Requirements: Windows 10 build 19041 (May 2020 Update) or later. Windows 11 works on all builds. The flag was backported to Windows 10 in build 19041 — earlier builds only support WDA_MONITOR (which blacks out the window instead of hiding it).
Electron API: setContentProtection()
Electron exposes this via BrowserWindow.setContentProtection(true). On Windows, this calls SetWindowDisplayAffinity(WDA_EXCLUDEFROMCAPTURE). On macOS, it calls CGWindowSetSharingType(kCGWindowSharingNone).
Basic usage:
// main.js — basic usage
const { BrowserWindow } = require('electron');
function createWindow() {
const win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: { nodeIntegration: true },
});
// This calls SetWindowDisplayAffinity(WDA_EXCLUDEFROMCAPTURE) on Windows
// On macOS it calls CGWindowSetSharingType(kCGWindowSharingNone)
win.setContentProtection(true);
win.loadFile('index.html');
}That's the entire API surface. One call. The complexity is in understanding the constraints and edge cases, which is what the rest of this guide covers.
Windows build version check
Before relying on WDA_EXCLUDEFROMCAPTURE, check the Windows build. On builds older than 19041, calling setContentProtection(true) applies WDA_MONITOR instead, which makes the window appear black (not invisible) in captures.
// Check Windows build before relying on WDA_EXCLUDEFROMCAPTURE
const os = require('os');
function supportsExcludeFromCapture() {
if (process.platform !== 'win32') return false;
const release = os.release(); // e.g. "10.0.19041"
const [, , build] = release.split('.').map(Number);
return build >= 19041; // May 2020 Update minimum
}
// In your main process:
if (supportsExcludeFromCapture()) {
win.setContentProtection(true);
} else {
console.warn('WDA_EXCLUDEFROMCAPTURE not supported on this Windows build');
}Runtime toggling
You can toggle the protection on and off at runtime. This is useful if you want to give users a "reveal" mode where the window becomes visible in screen captures temporarily.
// Toggle capture exclusion at runtime
let captureProtected = false;
ipcMain.handle('toggle-capture-protection', () => {
captureProtected = !captureProtected;
win.setContentProtection(captureProtected);
return captureProtected;
});Known edge cases
- Child windows inherit the flag — any
BrowserWindowopened as a child of a protected window also becomes capture-excluded. This is usually what you want. - The window IS visible on the physical display — only the capture pipeline is affected. Users sitting next to the machine can see the window normally.
- Screenshots via PrintScreen are excluded — the WDA flag blocks all Win32 capture methods including BitBlt, DDA, and WGC (Windows Graphics Capture). This is the same pipeline Zoom, OBS, and Game Bar use.
- Direct GPU capture can still capture it — DXGI-level capture (rarely used by consumer tools) can sometimes bypass the flag on certain GPU/driver combinations. Test with the specific tools your users use.
- Transparency + capture exclusion work together — you can have a transparent always-on-top window that is also capture-excluded. This is the combination GhostDesk uses.
How to verify it's working
// Verify the flag was applied (Windows-only debug)
// Open OBS or Windows Game Bar (Win+G) and check the preview.
// Your Electron window should be absent from the capture.
// Alternatively, use a secondary device on a Zoom call with yourself.OBS Studio is the best verification tool because it uses WGC (Windows Graphics Capture) — the same API Zoom, Teams, and Meet use. If OBS doesn't capture it, neither will video call software.
Why we built GhostDesk on this
GhostDesk is an AI overlay that floats above any Windows application and is completely invisible during screen shares. The entire privacy guarantee is built on setContentProtection(true) plus a transparent, always-on-top BrowserWindow.
We verify invisibility daily across 14+ platforms. If you're building something similar and want to compare notes, reach out at ghostdeskapp@gmail.com.