Skip to content

feat(desktop): keep windows and panels out of screen capture - #2834

Open
houko wants to merge 4 commits into
mainfrom
feat/2826-exclude-from-capture
Open

houko wants to merge 4 commits into
mainfrom
feat/2826-exclude-from-capture

Conversation

@houko

@houko houko commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Summary

Desktop apps can now keep a window or panel out of screenshots, screen recordings and screen sharing, as a recorder's HUD, a countdown, an annotation overlay or a password prompt needs.

  • ExcludeFromCapture on desktop.WindowOptions and desktop.PanelOptions applies it before the surface first shows, so no frame of it is captured.
  • nsgo.WindowExcludedFromCapture() does the same for the main window, alongside nsgo.SkipTaskbar() and nsgo.WindowNoShadow(), so a recorder whose main window is its HUD is never captured either.
  • desktop.SetWindowExcludedFromCapture turns it on or off later, and desktop.CanExcludeWindowsFromCapture says in a window's scope whether it takes effect.
  • macOS sets sharingType to NSWindowSharingNone, and back to NSWindowSharingReadOnly. AppKit documents this only as keeping other processes from reading the window's contents, so the docs say plainly that whether a given recorder leaves it out depends on the capture API it uses.
  • Windows calls SetWindowDisplayAffinity with WDA_EXCLUDEFROMCAPTURE, and WDA_NONE to turn it off. Before Windows 10 version 2004 (build 19041) the capability reads false. It does not fall back to WDA_MONITOR, which would show a black rectangle instead of hiding the window.
  • On Linux (X11 and Wayland), phones, the web, embedded views, the app's own hidden surface and tray icons, the capability reads false and the command does nothing.
  • Scope.Capture of an excluded window returns an error instead of an image. What the system's capture makes of an excluded window differs by API and OS version, and PrintWindow would bypass the exclusion on Windows.
  • nsgotest records the option on opened surfaces (SurfaceConfig.ExcludeFromCapture) and records the runtime request (WindowSetExcludedFromCapture).

On macOS 26.7, during a run over SSH with no display, a window that already had its window-server window stayed at NSWindowSharingNone after it was set back to read-only. A deferred window switched both ways. Because of this, the macOS backend tracks the sharing type the window reports, not the one it requested, and logs when the two differ, so an app is told rather than left with a window that silently stays excluded. The public docs, desktop.SetWindowExcludedFromCapture and the architecture doc say so.

Tests that read the screen:

  • macOS: TestWindowExcludedFromScreenCapture shows an opaque magenta window and reads the screen under it with screencapture, another process as a real recorder is. It checks that the colour is present before, absent while excluded and present again after setExcludedFromCapture(false), or, if the window server keeps the sharing type at none, that the surface still reports it excluded and the colour stays absent. A second, deferred window is excluded before it first shows and must never appear, then appear once the exclusion is off. It skips without a display or Screen Recording permission.
  • Windows: TestWindowExcludedFromCapture opens a magenta window and a smaller green window owned by it, so the green one stays above, with ExcludeFromCapture. The screen must show magenta where the green window is until its exclusion is turned off, then green. The magenta window is then toggled the same way.

Fixes #2826

Targets

  • Shared code (core, base, ui, tsx, the nsgo tool)
  • macOS
  • iOS
  • tvOS
  • watchOS
  • Android
  • Windows
  • Linux
  • Web
  • Mini programs
  • Docs or website only

Screenshots

None

Verification

  • head: 5e7e7e4ef58c730df9b031753a0c58fe37c9473a
  • base: b84aa6d55419ce37f3b640f8887fd0bcbf47aa6d
  • commands:
    • go tool nsgo check -target macos,windows,linux -jobs 6 → 0
    • go tool nsgo test ./core ./desktop ./nsgotest ./internal/driver ./internal/backend . → 0
    • go tool nsgo test -run 'TestWindowExcludedFromCapture|TestWindowExcludedFromScreenCapture|TestTransparentWindow$' ./internal/platform/macos → 0
    • go run ./tools/changelog check → 0
  • result: pass
  • not covered: These ran on a darwin/amd64 macOS 26 build host over SSH, with no display. nsgo check ran on 56ec8cdbe. The only later change is a skip message in a test, which the test runs above built. TestWindowExcludedFromScreenCapture skipped there because screencapture cannot read a screen without a display, so the pixel checks on macOS, including whether a window shown on a display really gets its read-only sharing type back, still need a run on a Mac with a display and Screen Recording permission for the terminal. The Windows TestWindowExcludedFromCapture was compiled and vetted, not run; it needs a Windows 10 version 2004 or later session with a desktop. nsgo.WindowExcludedFromCapture reaches SurfaceConfig through the same core.WindowOptions path that the core tests cover, but no native test opens a main window with it. Linux runtime tests and arm64 macOS were not run.

Checklist

  • The title is a Conventional Commit, such as fix(linux): keep the caret after a paste; a squash merge uses it as the commit subject.
  • Docs whose facts change are updated, and a capability users can see has a line in a changelog.d/ fragment, not in CHANGELOG.md.
  • New third-party code, assets and dependencies name their source and license.

houko added 4 commits December 1, 2026 11:26
Add ExcludeFromCapture to WindowOptions and PanelOptions, desktop.SetWindowExcludedFromCapture and desktop.CanExcludeWindowsFromCapture. macOS sets the window's sharing type to none; Windows 10 version 2004 and later set the display affinity WDA_EXCLUDEFROMCAPTURE, without falling back to WDA_MONITOR's black rectangle on earlier builds. Linux, phones and the web report it unavailable. Scope.Capture of an excluded window reports an error.

Fixes #2826
Add nsgo.WindowExcludedFromCapture so the main window, like any other, stays out of captures from its first frame on macOS and Windows.

Add a macOS test that reads the screen with screencapture under an excluded window and a window excluded before it first shows, and log when the sharing type macOS reports differs from the one set. Make the Windows pixel test open its windows through the engine, with the excluded one owned by the window read under it so it stays above.
@github-actions github-actions Bot added size/L local-ci-pass The head commit declares that its local checks passed enhancement New feature or request documentation Improvements or additions to documentation macOS Windows Linux core labels Dec 1, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core documentation Improvements or additions to documentation enhancement New feature or request Linux local-ci-pass The head commit declares that its local checks passed macOS size/L Windows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Desktop: no way to keep a window or panel out of screenshots and screen recordings (sharingType / WDA_EXCLUDEFROMCAPTURE)

1 participant