moeru-ai/airi · error · Error

checkMacOSScreenCapturePermission is only available on…

Error message

checkMacOSScreenCapturePermission is only available on macOS (darwin)

What it means

checkMacOSScreenCapturePermission() in packages/electron-screen-capture/src/main/utils.ts is a thin wrapper over Electron's systemPreferences.getMediaAccessStatus('screen'), which only exists on macOS. The guard throws immediately when process.platform is not darwin, because querying macOS privacy state (TCC) is meaningless elsewhere. The same handler is wired to the screenCapture.checkMacOSPermission eventa contract, so calling that invoke from a renderer on Windows/Linux propagates this error over IPC.

Solutions

  1. Gate the call by platform before invoking: if (process.platform === 'darwin') in main, or check the renderer's platform info before invoking screenCapture.checkMacOSPermission.
  2. On Windows/Linux, use the platform-appropriate path (e.g. Windows exposes screen capture without a TCC-style pre-check; just attempt getSources/getDisplayMedia and handle failure).
  3. In tests, stub the util or skip the spec on non-darwin runners (vitest describe.skipIf(process.platform !== 'darwin')).

Example fix

// before
const status = await invoke(screenCapture.checkMacOSPermission)

// after
const status = isMacOSRenderer
  ? await invoke(screenCapture.checkMacOSPermission)
  : 'granted' // non-macOS platforms have no pre-check; attempt capture directly
Defensive patterns

Strategy: validation

Validate before calling

const isDarwin = process.platform === 'darwin' // main process
if (isDarwin) {
  const status = checkMacOSScreenCapturePermission()
}

Prevention

When it happens

Trigger: Calling checkMacOSScreenCapturePermission() directly, or invoking screenCapture.checkMacOSPermission from the renderer, while running on Windows or Linux. Also happens when platform-gating code lives only in the UI layer but the invoke path is reachable from shared code, or when tests run on a Linux CI box against code written on a Mac.

Common situations: Cross-platform feature checks written on macOS; CI on Linux executing permission-related code paths; forgetting that a shared composable calls the macOS-only invoke unconditionally.

Related errors


AI-assisted analysis of moeru-ai/airi@677329427f (2026-08-18). Data as JSON: /api/errors/32053dfc9c3af7ad. Report an issue: GitHub.

Appendix: source

Thrown at packages/electron-screen-capture/src/main/utils.ts:33

 * - {@link https://github.com/electron/electron/issues/27024}
 * - {@link https://github.com/electron/electron/issues/34905}
 *
 * @param source - The DesktopCapturerSource to serialize
 * @returns A serializable representation of the DesktopCapturerSource
 */
export function toSerializableDesktopCapturerSource(source: DesktopCapturerSource): SerializableDesktopCapturerSource {
  return {
    id: source.id,
    name: source.name,
    display_id: source.display_id,
    appIcon: source.appIcon != null && !source.appIcon.isEmpty() ? new Uint8Array(source.appIcon.toPNG().buffer) : undefined,
    thumbnail: source.thumbnail != null ? new Uint8Array(source.thumbnail.toJPEG(90).buffer) : undefined,
  }
}

export function checkMacOSScreenCapturePermission(): ReturnType<typeof systemPreferences.getMediaAccessStatus> {
  if (!isMacOS) {
    throw new Error('checkMacOSScreenCapturePermission is only available on macOS (darwin)')
  }

  return systemPreferences.getMediaAccessStatus('screen')
}

export function requestMacOSScreenCapturePermission(): void {
  if (!isMacOS) {
    throw new Error('requestMacOSScreenCapturePermission is only available on macOS (darwin)')
  }

  shell.openExternal('x-apple.systempreferences:com.apple.preference.security?Privacy_ScreenCapture')
}

View on GitHub (pinned to 677329427f)