{"record":{"id":"32053dfc9c3af7ad","repo":"moeru-ai/airi","slug":"checkmacosscreencapturepermission-is-only-availabl","errorCode":null,"errorMessage":"checkMacOSScreenCapturePermission is only available on macOS (darwin)","messagePattern":"checkMacOSScreenCapturePermission is only available on macOS \\(darwin\\)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/electron-screen-capture/src/main/utils.ts","lineNumber":33,"sourceCode":" * - {@link https://github.com/electron/electron/issues/27024}\n * - {@link https://github.com/electron/electron/issues/34905}\n *\n * @param source - The DesktopCapturerSource to serialize\n * @returns A serializable representation of the DesktopCapturerSource\n */\nexport function toSerializableDesktopCapturerSource(source: DesktopCapturerSource): SerializableDesktopCapturerSource {\n  return {\n    id: source.id,\n    name: source.name,\n    display_id: source.display_id,\n    appIcon: source.appIcon != null && !source.appIcon.isEmpty() ? new Uint8Array(source.appIcon.toPNG().buffer) : undefined,\n    thumbnail: source.thumbnail != null ? new Uint8Array(source.thumbnail.toJPEG(90).buffer) : undefined,\n  }\n}\n\nexport function checkMacOSScreenCapturePermission(): ReturnType<typeof systemPreferences.getMediaAccessStatus> {\n  if (!isMacOS) {\n    throw new Error('checkMacOSScreenCapturePermission is only available on macOS (darwin)')\n  }\n\n  return systemPreferences.getMediaAccessStatus('screen')\n}\n\nexport function requestMacOSScreenCapturePermission(): void {\n  if (!isMacOS) {\n    throw new Error('requestMacOSScreenCapturePermission is only available on macOS (darwin)')\n  }\n\n  shell.openExternal('x-apple.systempreferences:com.apple.preference.security?Privacy_ScreenCapture')\n}\n","sourceCodeStart":15,"sourceCodeEnd":46,"githubUrl":"https://github.com/moeru-ai/airi/blob/27111382b4a79a7e983289d6e983a06af185ed0f/packages/electron-screen-capture/src/main/utils.ts#L15-L46","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Gate the renderer call on platform detection before invoking checkMacOSPermission.","Wrap the call in try/catch and treat a thrown error as 'permission not applicable' on non-mac.","Do not surface this error to end users on non-mac platforms; skip the macOS permission step entirely."],"exampleFix":"// before\nconst status = await invoke(screenCapture.checkMacOSPermission)\n// after\nif (process.platform === 'darwin') {\n  const status = await invoke(screenCapture.checkMacOSPermission)\n} else {\n  // non-macOS: screen capture permission gate does not apply\n}","handlingStrategy":"type-guard","validationCode":"import { isMacOS } from 'std-env'\n\nif (isMacOS) {\n  const status = checkMacOSScreenCapturePermission()\n  // proceed\n} else {\n  // screen-capture permission gate does not apply on this platform\n}","typeGuard":"import { isMacOS } from 'std-env'\n\nfunction onMacOS(): boolean { return isMacOS }","tryCatchPattern":"try {\n  await invoke(screenCapture.checkMacOSPermission)\n} catch (error) {\n  if (error instanceof Error && error.message.includes('only available on macOS')) {\n    // non-mac: treat as 'not applicable'\n  } else throw error\n}","preventionTips":["Gate macOS permission calls behind platform detection in renderer code.","Hide macOS-specific permission UI on Windows/Linux.","Run renderer tests that touch this handler only on macOS runners."],"tags":["electron","screen-capture","platform","macos"],"backgroundTag":null,"analyzedSha":"27111382b4a79a7e983289d6e983a06af185ed0f","analyzedAt":"2026-08-12T18:33:34.132Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}