moeru-ai/airi · error · Error

checkMacOSScreenCapturePermission is only available on macOS

Error message

checkMacOSScreenCapturePermission is only available on macOS (darwin)

What it means

Thrown by checkMacOSScreenCapturePermission() when std-env's isMacOS is false. The function wraps systemPreferences.getMediaAccessStatus('screen'), which is a darwin-only Electron API, so calling it on Windows or Linux would crash regardless. The guard makes the platform requirement explicit.

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 27111382b4)

Solutions

  1. Gate the renderer call on platform detection before invoking checkMacOSPermission.
  2. Wrap the call in try/catch and treat a thrown error as 'permission not applicable' on non-mac.
  3. Do not surface this error to end users on non-mac platforms; skip the macOS permission step entirely.

Example fix

// before
const status = await invoke(screenCapture.checkMacOSPermission)
// after
if (process.platform === 'darwin') {
  const status = await invoke(screenCapture.checkMacOSPermission)
} else {
  // non-macOS: screen capture permission gate does not apply
}
Defensive patterns

Strategy: type-guard

Validate before calling

import { isMacOS } from 'std-env'

if (isMacOS) {
  const status = checkMacOSScreenCapturePermission()
  // proceed
} else {
  // screen-capture permission gate does not apply on this platform
}

Type guard

import { isMacOS } from 'std-env'

function onMacOS(): boolean { return isMacOS }

Try / catch

try {
  await invoke(screenCapture.checkMacOSPermission)
} catch (error) {
  if (error instanceof Error && error.message.includes('only available on macOS')) {
    // non-mac: treat as 'not applicable'
  } else throw error
}

Prevention

When it happens

Trigger: Calling checkMacOSScreenCapturePermission() directly, or via the screenCapture.checkMacOSPermission invoke handler, on a non-darwin platform. The handler is installed unconditionally by initScreenCaptureForWindow, so any renderer invoke on Windows/Linux hits this.

Common situations: Cross-platform renderer code that unconditionally calls the macOS permission check; a dev testing on Linux/Windows without guarding the call; CI running renderer tests that exercise the permission flow on non-mac runners.

Related errors


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