fix(cua-driver-rs): drop bogus window-enum fallback in screen-recording probe - #1562
Conversation
…ng probe
`screen_recording_granted()` fell back to `!all_windows().is_empty()` when
`CGPreflightScreenCaptureAccess` reported false, on the theory that
`CGWindowListCopyWindowInfo` returning real windows implied the grant
was active. That theory is wrong: `CGWindowListCopyWindowInfo` returns
window IDs and bounds for any process without requiring the Screen
Recording grant — only window titles are gated. The fallback therefore
returned `true` on any populated desktop regardless of grant state,
which:
- made `check_permissions` report a false positive after
`tccutil reset ScreenCapture com.trycua.driver`, and
- short-circuited the startup permissions gate's prompt
(`gate.rs:213` early-returns on `status.all_granted()`) for users
who had never granted Screen Recording.
Drop the fallback entirely — `CGPreflightScreenCaptureAccess` is
Apple's documented preflight API for this grant and is accurate on
macOS 11+. The Cargo.lock churn is the v0.2.4 workspace bump
catching up — `release-bump-version.yml` didn't refresh the lock when
it pushed the version commit; `cargo check` on this branch did.
Related to #1561 (`check_permissions` stale-state report). The AX
side of that issue is a separate concern: `AXIsProcessTrusted()` is
the right API, but TCC attributes shell-invoked CLI processes to the
parent terminal — so a shell with AX granted will make
`cua-driver check_permissions` always see `accessibility: true`,
regardless of `com.trycua.driver`'s grant. That's a process-attribution
question, not a probe bug, and warrants its own investigation.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
📝 WalkthroughWalkthroughThis PR refactors macOS Screen Recording permission detection to use Apple's ChangesScreen Recording Permission Probe Refactor
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@libs/cua-driver-rs/crates/platform-macos/src/permissions/status.rs`:
- Around line 30-35: The CGPreflightScreenCaptureAccess call in
libs/cua-driver-rs/crates/platform-macos/src/permissions/status.rs is only
available on macOS 11+, but the crate still exposes older macOS feature flags
(e.g., "elcapitan", "highsierra") causing link failures; either update the
crate's supported macOS minimum to 11.0 by removing/adjusting those older
feature flags in Cargo.toml and any platform feature gating, or add a version
gate/fallback in permissions/status.rs so calls to
CGPreflightScreenCaptureAccess are only compiled/linked for macOS >= 11.0 (and
provide an alternative code path for older macOS targets); refer to the
CGPreflightScreenCaptureAccess symbol and the permissions/status.rs module when
making the change.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 55de892f-e272-42e9-9903-5129ab9ffd20
⛔ Files ignored due to path filters (1)
libs/cua-driver-rs/Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (1)
libs/cua-driver-rs/crates/platform-macos/src/permissions/status.rs
| /// Mirrors Swift `Permissions.currentStatus()`. Difference: Swift uses | ||
| /// `SCShareableContent.excludingDesktopWindows` (ScreenCaptureKit) for | ||
| /// the screen recording probe, which is unavailable from Rust without | ||
| /// large bindings — same caveat documented in `check_permissions.rs`. | ||
| /// large bindings. `CGPreflightScreenCaptureAccess` is Apple's | ||
| /// documented preflight API for the same grant and is accurate on | ||
| /// macOS 11+. |
There was a problem hiding this comment.
🧩 Analysis chain
🌐 Web query:
What is the minimum macOS version that supports CGPreflightScreenCaptureAccess API?
💡 Result:
The CGPreflightScreenCaptureAccess API was introduced in macOS 11.0 [1]. It is used to check whether an application has permission to capture the screen [1]. As of May 2026, Apple recommends that developers transition to the ScreenCaptureKit framework for screen recording functionality [2].
Citations:
- 1: https://stackoverflow.com/questions/70537845/cgpreflightscreencaptureaccess-always-returns-false-in-development-builds
- 2: Mac Sequoia 15.1 Deprecation of CGPreflightScreenCaptureAccess nashaofu/xcap#160
🏁 Script executed:
find . -name "Cargo.toml" -o -name ".github" -type d -o -name "*.yml" -path "*/.github/*" | head -20Repository: trycua/cua
Length of output: 824
🏁 Script executed:
rg "macos|rust-version|minimum" -i $(find . -name "Cargo.toml" | head -5) -A 2Repository: trycua/cua
Length of output: 899
🏁 Script executed:
cat -n libs/cua-driver-rs/crates/platform-macos/Cargo.tomlRepository: trycua/cua
Length of output: 2048
🏁 Script executed:
rg "macos|deployment|target" .github/workflows/*.yml | grep -i macos | head -20Repository: trycua/cua
Length of output: 1583
🏁 Script executed:
sed -n '48,67p' libs/cua-driver-rs/crates/platform-macos/src/permissions/status.rsRepository: trycua/cua
Length of output: 1101
Add macOS version check or update minimum version requirement.
CGPreflightScreenCaptureAccess is only available on macOS 11.0+, but your project's Cargo.toml includes features for older macOS versions (e.g., "elcapitan" for 10.11, "highsierra" for 10.13). The current implementation will fail to link on macOS 10.15 and earlier.
Either:
- Drop support for older macOS and update minimum version to 11.0, or
- Add a version gate or fallback for older versions
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@libs/cua-driver-rs/crates/platform-macos/src/permissions/status.rs` around
lines 30 - 35, The CGPreflightScreenCaptureAccess call in
libs/cua-driver-rs/crates/platform-macos/src/permissions/status.rs is only
available on macOS 11+, but the crate still exposes older macOS feature flags
(e.g., "elcapitan", "highsierra") causing link failures; either update the
crate's supported macOS minimum to 11.0 by removing/adjusting those older
feature flags in Cargo.toml and any platform feature gating, or add a version
gate/fallback in permissions/status.rs so calls to
CGPreflightScreenCaptureAccess are only compiled/linked for macOS >= 11.0 (and
provide an alternative code path for older macOS targets); refer to the
CGPreflightScreenCaptureAccess symbol and the permissions/status.rs module when
making the change.
Summary
permissions::status::screen_recording_granted()had a heuristic fallback whenCGPreflightScreenCaptureAccessreturned false:!crate::windows::all_windows().is_empty(). The theory was that getting non-empty results fromCGWindowListCopyWindowInfoimplied the Screen Recording grant was active. That theory is wrong —CGWindowListCopyWindowInforeturns window IDs and bounds for any process without requiring the Screen Recording grant; only window titles are gated. So the fallback returned `true` on any populated desktop regardless of grant state.Two user-visible bugs follow from this:
tccutil reset Accessibility com.trycua.driver(macOS) #1561 — the SR half, anyway; the AX half is a separate concern (see below).The fix is to remove the fallback entirely and trust `CGPreflightScreenCaptureAccess` — Apple's documented preflight API for this grant, accurate on macOS 11+.
Files changed
On the AX side of #1561
The umbrella issue (#1561) reported that both `accessibility` and `screen_recording` come back `true` after `tccutil reset`. The SR side is a probe bug, fixed here. The AX side is a TCC attribution question: `AXIsProcessTrusted()` is the right API, but TCC attributes shell-invoked CLI processes to the parent terminal — so any shell that already has AX granted (Terminal, Claude Code, iTerm) will make `cua-driver check_permissions` see `accessibility: true` no matter what `com.trycua.driver` has in TCC. That's a fundamentally separate problem from this fix; tracking it on #1561.
Test plan
Related
tccutil reset Accessibility com.trycua.driver(macOS) #1561🤖 Generated with Claude Code
Summary by CodeRabbit