UNPKG

ai-debug-local-mcp

Version:

🎯 ENHANCED AI GUIDANCE v4.1.2: Dramatically improved tool descriptions help AI users choose the right tools instead of 'close enough' options. Ultra-fast keyboard automation (10x speed), universal recording, multi-ecosystem debugging support, and compreh

163 lines • 5.76 kB
/** * DebugSessionCoordinator - Coordinates all debugging session lifecycle functionality * * This coordinator consolidates core debugging session management including page attachment, * state capture, debug code injection, element inspection, and comprehensive page state * extraction into a unified interface, reducing complexity in LocalDebugEngine. */ export class DebugSessionCoordinator { stateCapture; debugInjector; frameworkDetector; constructor(stateCapture, debugInjector, frameworkDetector) { this.stateCapture = stateCapture; this.debugInjector = debugInjector; this.frameworkDetector = frameworkDetector; } /** * Coordinate page attachment across all debugging modules */ async attachToPage(page) { try { // Validate page before attaching if (!page || page.isClosed()) { throw new Error('Cannot attach to closed or invalid page'); } // Attach StateCapture for state management await this.stateCapture.attachToPage(page); // Detect framework and attach framework-specific engines const frameworkResult = await this.frameworkDetector.detectFramework(page); await this.frameworkDetector.attachFrameworkEngines(page); return frameworkResult; } catch (error) { if (error.message.includes('Target page, context or browser has been closed')) { throw new Error('Cannot attach to debugging session - browser context is closed'); } throw error; } } /** * Capture comprehensive debugging session state */ async captureSessionState() { try { return await this.stateCapture.captureState(); } catch (error) { if (error.message.includes('Target page, context or browser has been closed')) { // Return minimal state when browser is closed return { url: 'about:blank', localStorage: {}, sessionStorage: {}, cookies: [], timestamp: new Date() }; } throw error; } } /** * Capture DOM snapshot for debugging analysis */ async captureDOMSnapshot() { try { return await this.stateCapture.captureDOMSnapshot(); } catch (error) { if (error.message.includes('Target page, context or browser has been closed')) { // Return minimal DOM snapshot when browser is closed return { html: '<html><head></head><body>Browser context closed</body></html>', structure: { tagName: 'html', attributes: {}, children: [], textContent: 'Browser context closed' }, timestamp: new Date() }; } throw error; } } /** * Inject debugging code directly into the page */ async injectDebuggingCode(page, code) { try { if (!page) { throw new Error('No page provided'); } if (page.isClosed()) { throw new Error('Cannot inject debugging code - page is closed'); } return await page.evaluate(code); } catch (error) { if (error.message.includes('Target page, context or browser has been closed')) { throw new Error('Cannot inject debugging code - browser context is closed'); } throw error; } } /** * Inject framework-specific debugging code */ async injectFrameworkDebugging(page, framework) { return await this.debugInjector.injectDebugging(page, framework); } /** * Capture variable state with specific scope */ async captureVariableState(variablePath, scope) { return await this.stateCapture.captureVariableState(variablePath, scope); } /** * Extract comprehensive page state including framework-specific data */ async extractPageState(page) { const state = await this.captureSessionState(); const dom = await this.captureDOMSnapshot(); const frameworkResult = await this.frameworkDetector.detectFramework(page); let frameworkState = null; if (frameworkResult.framework === 'phoenix') { frameworkState = await this.stateCapture.findPhoenixLiveViewState(); } else if (frameworkResult.framework === 'react') { frameworkState = await this.stateCapture.findReactComponents(); } return { ...state, dom, framework: frameworkResult.framework, frameworkState }; } /** * Get React component tree (delegated to StateCapture) */ async getReactComponentTree() { return await this.stateCapture.getReactComponentTree(); } /** * Get React state (delegated to StateCapture) */ async getReactState() { return await this.stateCapture.getReactState(); } /** * Find React components (delegated to StateCapture) */ async findReactComponents() { return await this.stateCapture.findReactComponents(); } /** * Find Phoenix LiveView state (delegated to StateCapture) */ async findPhoenixLiveViewState() { return await this.stateCapture.findPhoenixLiveViewState(); } } //# sourceMappingURL=debug-session-coordinator.js.map