This commit is contained in:
Francesco Renzi
2026-01-15 22:42:41 +00:00
parent f1a0d1a9f8
commit 2800573f56

View File

@@ -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();
}
}
}
});