{"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/677329427f32468c74b17f3ec47eeca4e05bec65/packages/electron-screen-capture/src/main/utils.ts#L15-L46","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Gate the call by platform before invoking: if (process.platform === 'darwin') in main, or check the renderer's platform info before invoking screenCapture.checkMacOSPermission.","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).","In tests, stub the util or skip the spec on non-darwin runners (vitest describe.skipIf(process.platform !== 'darwin'))."],"exampleFix":"// before\nconst status = await invoke(screenCapture.checkMacOSPermission)\n\n// after\nconst status = isMacOSRenderer\n  ? await invoke(screenCapture.checkMacOSPermission)\n  : 'granted' // non-macOS platforms have no pre-check; attempt capture directly","handlingStrategy":"validation","validationCode":"const isDarwin = process.platform === 'darwin' // main process\nif (isDarwin) {\n  const status = checkMacOSScreenCapturePermission()\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep the platform check next to every macOS-only permission call — in shared code, gate both the UI affordance and the invoke.","Write platform-dependent permission flows behind a small platform adapter so non-darwin branches cannot reach the call.","Mark macOS-only specs with describe.skipIf(process.platform !== 'darwin') so Linux CI never trips it."],"tags":["electron","macos","platform-guard","permissions","screen-capture"],"backgroundTag":"platform-not-supported","analyzedSha":"677329427f32468c74b17f3ec47eeca4e05bec65","analyzedAt":"2026-08-18T17:29:58.153Z","contentChangedAt":"2026-08-18T17:29:58.153Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}