in src/extension.ts [401:432]
export async function attachToCurrentDebugTarget(context: vscode.ExtensionContext, debugSessionId?: string): Promise<void> {
if (!telemetryReporter) {
telemetryReporter = createTelemetryReporter(context);
}
telemetryReporter.sendTelemetryEvent('command/attachToCurrentDebugTarget');
const sessionId = debugSessionId || getActiveDebugSessionId();
if (!sessionId) {
const errorMessage = 'No active debug session';
telemetryReporter.sendTelemetryErrorEvent('command/attachToCurrentDebugTarget/devtools', {message: errorMessage});
void vscode.window.showErrorMessage(errorMessage);
return;
}
const targetWebsocketUrl = await getJsDebugCDPProxyWebsocketUrl(sessionId);
if (targetWebsocketUrl instanceof Error) {
telemetryReporter.sendTelemetryErrorEvent('command/attachToCurrentDebugTarget/devtools', {message: targetWebsocketUrl.message});
void vscode.window.showErrorMessage(targetWebsocketUrl.message);
} else if (targetWebsocketUrl) {
// Auto connect to found target
telemetryReporter.sendTelemetryEvent('command/attachToCurrentDebugTarget/devtools');
const runtimeConfig = getRuntimeConfig();
runtimeConfig.isJsDebugProxiedCDPConnection = true;
DevToolsPanel.createOrShow(context, telemetryReporter, targetWebsocketUrl, runtimeConfig);
} else {
const errorMessage = 'Unable to attach DevTools to current debug session.';
telemetryReporter.sendTelemetryErrorEvent('command/attachToCurrentDebugTarget/devtools', {message: errorMessage});
void vscode.window.showErrorMessage(errorMessage);
}
}