How I made a window invisible to screen sharing on macOS (and checked that it really is)
说明与用途
NSWindowSharingNone 标志在 macOS 上隐藏窗口,避免屏幕共享时泄露内容。测试脚本验证隐藏窗口在三种捕获方法中均无像素,但需在系统更新后持续验证。
问题
Ensuring a floating window in a macOS app remains hidden from screen‑sharing captures while still visible to the local user.
结果
The NSWindowSharingNone flag successfully hides the window from all tested screen‑capture methods on macOS 26.6.2. The test script confirms zero pixels of the hidden window in captures while the normal window is fully captured.
工作流
- 1. Set the NSWindow's sharingType to NSWindowSharingNone via PyObjC.
- 2. Configure window level, collection behavior, and hide‑on‑deactivate settings to keep it on top and across Spaces.
- 3. Create a test with two windows (magenta hidden, green normal).
- 4. Capture the screen using ScreenCaptureKit, macOS screencapture, and CGWindowListCreateImage.
- 5. Count pixels of each color in the captures using NumPy.
- 6. Verify the green window appears in all captures and the magenta window appears in none.
- 7. Run the test after each macOS update to ensure continued compliance.
证据
Every NSWindow has a sharingType. Set it to NSWindowSharingNone and macOS leaves the window out of screen captures.
On my MacBook (macOS 26.6.2, October 2026): 0 pixels of the hidden window in all three captures, while the ordinary window was captured every time (between 93k and 369k pixels, depending on the capture).
ScreenCaptureKit still lists the window. Its title and position show up in the list of shareable windows. It just isn't drawn in the image.
- 记录日期: 2026-11-03T18:29:04.001Z