This guide explains how to debug the Electron application effectively during development.
- Open the workspace in VS Code
- Press F5 or go to
Run and Debug→Debug Electron (Full) - Set breakpoints in your code
- Use the Debug Console to inspect variables
cd electron-app
npm run devThis starts the app with:
- DevTools automatically opened
- Debug panel available (Ctrl+Shift+D)
- Enhanced error tracking
- Performance monitoring
- Debug variables exposed globally
cd electron-app
npm run debugThis enables Node.js debugging on port 5858 for the main process.
The debug features are automatically disabled in production builds and only available when:
- Running with
npm run dev(--dev flag) - NODE_ENV=development
- ELECTRON_IS_DEV=1
A floating debug panel with quick actions:
- Dump State: Show current application state
- Test Generation: Verify all generation functions work
- Memory Usage: Display current memory consumption
- Inspect Selected: Examine the currently selected node
All debug utilities are available via window.debug or window.DEBUG:
// Application state
debug.appState // Current app state
debug.settings // User settings
debug.rootNodes // All root nodes
// Core components
debug.treeView // Tree view instance
debug.documentViewer // Document viewer instance
debug.workspace // Workspace manager
// Quick actions
debug.dumpState() // Show full application state
debug.inspectNode() // Inspect selected node (or pass a node)
debug.testGeneration() // Test all generation functions
debug.checkMemory() // Show memory usage
// Performance testing
debug.measureGeneration('System', 10) // Measure 10 system generations
// Node creation helpers
debug.createSystem() // Create and generate a system
debug.createPlanet() // Create and generate a planet
// Error tracking
debug.getErrors() // Get all tracked errors
debug.clearErrors() // Clear error historyDevelopment mode adds colored console output:
- [LOG] - Blue for general messages
- [ERROR] - Red for errors
- [WARN] - Orange for warnings
- [DEBUG] - Green for debug messages
- [GENERATION] - Purple for generation events
Automatic timing for:
- Node creation operations
- Tree view updates
- Generation performance
All unhandled errors and promise rejections are tracked and available via debug.getErrors().
// Test a specific generation type
debug.measureGeneration('System', 1);
// Inspect the generated node
const system = debug.createSystem();
debug.inspectNode(system);
// Check for errors during generation
debug.testGeneration();-
Use DevTools Elements panel to inspect HTML/CSS
-
Use Console to interact with components:
debug.treeView.getAllNodes() // Get all tree nodes debug.documentViewer.refresh() // Refresh document view
-
Check component state:
debug.dumpState(); // See everything at once
// Check memory usage
debug.checkMemory();
// Measure generation performance
debug.measureGeneration('System', 50);
// Monitor specific operations
console.time('My Operation');
// ... do something ...
console.timeEnd('My Operation');// Examine current state
debug.dumpState();
// Check specific settings
debug.settings.enabledBooks;
debug.settings.xenosGeneratorSources;
// Inspect tree structure
debug.treeView.expandedNodes;
debug.rootNodes.length;The workspace includes several debug configurations:
- Debugs the Node.js main process (main.js)
- Set breakpoints in main.js, IPC handlers, menu logic
- Debugs the renderer process (web content)
- Set breakpoints in app.js, UI components, generation logic
- Debugs both main and renderer processes simultaneously
- Recommended for most debugging scenarios
- F5: Start debugging (VS Code)
- F12: Toggle DevTools
- Ctrl+Shift+I: Toggle DevTools (alternative)
- Ctrl+Shift+D: Toggle debug panel
- Ctrl+F5: Force reload
- F11: Toggle fullscreen
- Ensure you're running with
npm run dev(notnpm start) - Check console for "Debug tools initialized" message
- Verify
process.argvincludes--dev
- Try manually: View menu → Toggle Developer Tools
- Check if
isDevis true in main process - Restart with
npm run dev
- Ensure source maps are enabled (they are by default)
- Try debugging with "Debug Electron (Full)" configuration
- Check that files are not minified
- Debug mode adds overhead for tracking and logging
- Use
npm startfor production performance testing - Monitor memory usage with
debug.checkMemory()
All debug features are automatically disabled in production builds to ensure:
- No performance overhead
- No security risks from exposed debug variables
- Clean console output
- Professional user experience
The debug tools check multiple conditions:
process.argv.includes('--dev')process.env.NODE_ENV === 'development'process.env.ELECTRON_IS_DEV === '1'
If none of these are true, debug tools won't initialize.