diff --git a/browser-ext/content/content.js b/browser-ext/content/content.js index 2be7acdc1..952062de0 100644 --- a/browser-ext/content/content.js +++ b/browser-ext/content/content.js @@ -556,6 +556,39 @@ function handleTerminatedEvent() { } } +/** + * Load current debug state (used when page loads while already paused) + */ +async function loadCurrentDebugState() { + if (!debuggerPane) return; + + try { + const stackTrace = await sendDapRequest('stackTrace', { threadId: 1 }); + if (stackTrace.stackFrames && stackTrace.stackFrames.length > 0) { + const currentFrame = stackTrace.stackFrames[0]; + currentFrameId = currentFrame.id; + + // Move pane to current step + const stepName = currentFrame.name; + const stepElement = findStepByName(stepName); + if (stepElement) { + moveDebuggerPane(stepElement, stepName); + } + + // Update step counter + const counter = debuggerPane.querySelector('.dap-step-counter'); + if (counter) { + counter.textContent = `Step ${currentFrame.id + 1} of ${stackTrace.stackFrames.length}`; + } + + // Load scopes + await loadScopes(currentFrame.id); + } + } catch (error) { + console.error('[Content] Failed to load current debug state:', error); + } +} + /** * Handle status change from background */ @@ -703,9 +736,10 @@ function init() { injectDebugButton(); // Check current connection status - chrome.runtime.sendMessage({ type: 'get-status' }, (response) => { + chrome.runtime.sendMessage({ type: 'get-status' }, async (response) => { if (response && response.status) { handleStatusChange(response.status); + // If already connected/paused, auto-show the debugger pane if (response.status === 'paused' || response.status === 'connected') { const pane = document.querySelector('.dap-debugger-pane'); @@ -714,6 +748,11 @@ function init() { const btn = document.querySelector('.dap-debug-btn'); if (btn) btn.classList.add('selected'); } + + // If already paused, load the current debug state + if (response.status === 'paused') { + await loadCurrentDebugState(); + } } } });