This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
ELECTRON-FIRST PRIORITY: node-mac-recorder is a Node.js native addon specifically designed and optimized for Electron.js applications. It provides macOS screen recording capabilities using ScreenCaptureKit (macOS 15+) and AVFoundation (macOS 13+). The package allows recording of full screens, specific windows, or custom areas, with support for multi-display setups, audio capture, and cursor tracking.
This module is PRIMARILY BUILT FOR ELECTRON.JS. All features work seamlessly in Electron applications without any restrictions. Both ScreenCaptureKit and AVFoundation are fully supported in Electron environments.
npm run build # Build the native module using node-gyp
npm run rebuild # Clean rebuild of the native module
npm run clean # Clean build artifacts
npm install # Runs install.js which builds the module automaticallynpm test # Run the main test suite (test.js)
node cursor-test.js # Test cursor tracking functionality only
node test.js # Run comprehensive API testsThe package uses node-gyp for building the native C++/Objective-C module. Requires:
- macOS 10.15+ (Catalina or later)
- Xcode Command Line Tools
- Node.js 14+
Main Entry Point
index.js- Main MacRecorder class (EventEmitter-based)- Handles all high-level recording operations and coordinate transformations
Native Module (src/)
mac_recorder.mm- Main native module entry point and N-API bindingsscreen_capture.mm- AVFoundation-based screen/window recordingaudio_capture.mm- Audio device enumeration and capturecursor_tracker.mm- Real-time cursor position and event tracking
Build Configuration
binding.gyp- Native module build configuration- Links against AVFoundation, ScreenCaptureKit, AppKit, and other macOS frameworks
- Multi-Display Support: Automatic display detection and coordinate conversion
- Window Recording: Smart window detection with thumbnail generation
- Audio Control: Separate microphone and system audio controls with device selection
- Cursor Tracking: Real-time cursor position, type, and click event capture
- Permission Management: Built-in macOS permission checking and requesting
The package handles complex multi-display coordinate transformations:
- Global macOS coordinates (can be negative for secondary displays)
- Display-relative coordinates (always positive, 0-based)
- Automatic window-to-display mapping for recording
startRecording(outputPath, options)- Begin screen/window recordingstopRecording()- Stop recording and finalize video filegetWindows()- List all recordable application windowsgetDisplays()- Get all available displays with metadatagetAudioDevices()- Enumerate available audio input devicescheckPermissions()- Verify macOS recording permissions
startCursorCapture(filepath, options)- Begin real-time cursor tracking to JSONoptions.windowInfo- Window information for window-relative coordinatesoptions.windowRelative- Set to true for window-relative coordinates
stopCursorCapture()- Stop tracking and close output filegetCursorPosition()- Get current cursor position and state
The MacRecorder class emits the following events:
recordingStarted- Emitted immediately when recording starts with recording detailsstarted- Emitted when recording is confirmed started (legacy event)stopped- Emitted when recording stopscompleted- Emitted when recording file is finalizedtimeUpdate- Emitted every second with elapsed timecursorCaptureStarted- Emitted when cursor capture beginscursorCaptureStopped- Emitted when cursor capture ends
getWindowThumbnail(windowId, options)- Capture window preview imagegetDisplayThumbnail(displayId, options)- Capture display preview image
- Use
npm testfor full API validation cursor-test.jsfor testing cursor tracking specifically- Test files create output in
test-output/directory
- All recording operations are Promise-based
- Event emission for recording state changes (
recordingStarted,started,stopped,completed) recordingStartedevent provides immediate notification with recording details- Automatic permission checking before operations
- Error handling with descriptive messages for permission issues
- Cursor tracking supports multiple coordinate systems:
- Global coordinates (default)
- Display-relative coordinates (when recording)
- Window-relative coordinates (with windowInfo parameter)
ELECTRON-FIRST ARCHITECTURE:
- Primary Target: Electron.js applications (full support, no restrictions)
- Secondary: Node.js standalone applications
- macOS only (enforced in install.js)
- Native module compilation required on install
- Requires screen recording and accessibility permissions
Framework Selection Logic (Electron Priority):
- macOS 15+ + Electron: ScreenCaptureKit with full capabilities
- macOS 15+ + Node.js: ScreenCaptureKit with full capabilities
- macOS 14 + Electron: AVFoundation with full capabilities
- macOS 13 + Electron: AVFoundation with limited features
- macOS 14 + Node.js: AVFoundation with full capabilities
- macOS 13 + Node.js: AVFoundation with limited features
- Video recordings:
.movformat (H.264/AAC) - Cursor data: JSON format with timestamped events
x,y: Cursor coordinates (coordinate system dependent)timestamp: Time from capture start (ms)unixTimeMs: Unix timestampcursorType: macOS cursor typetype: Event type (move, click, etc.)coordinateSystem: "global", "display-relative", or "window-relative"windowInfo: Window metadata (when using window-relative coordinates)
- Thumbnails: Base64-encoded PNG data URIs
- Ensure Xcode Command Line Tools:
xcode-select --install - Clean rebuild:
npm run clean && npm run build - Check Node.js version compatibility (14+)
- Permission failures: Check System Preferences > Security & Privacy
- Recording failures: Verify target windows/displays are accessible
- Audio issues: Check audio device availability and permissions
The module tries loading from build/Release/ first, then falls back to build/Debug/ with helpful error messages if neither exists.
ELECTRON.JS IS THE PRIMARY TARGET:
- No Electron Restrictions: All Electron detection logic is for optimization, NOT blocking
- Framework Support: Both ScreenCaptureKit and AVFoundation work perfectly in Electron
- Environment Detection: Code detects Electron to provide enhanced logging and optimization
- macOS Compatibility:
- macOS 15+ (Sequoia+): Use ScreenCaptureKit for best performance
- macOS 14 (Sonoma): Use AVFoundation with full feature set
- macOS 13 (Ventura): Use AVFoundation with basic features
- Error Handling: Any "Recording failed to start" errors should trigger fallback logic, never blocking
NEVER BLOCK ELECTRON ENVIRONMENTS - This is a core design principle.