From 9009aeb1ffe10c701133d27ffc2b8adefc05e9e3 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Wed, 12 Nov 2025 10:35:42 +0000
Subject: [PATCH 1/4] Initial plan
From 243718ac749e0865f21ede6052a9df7057482112 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Wed, 12 Nov 2025 10:41:48 +0000
Subject: [PATCH 2/4] Initial exploration of vscode-js-debug structure
Co-authored-by: hediet <2931520+hediet@users.noreply.github.com>
---
OPTIONS.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/OPTIONS.md b/OPTIONS.md
index bc9ffac63..709c8d20d 100644
--- a/OPTIONS.md
+++ b/OPTIONS.md
@@ -437,3 +437,4 @@
"!**/node_modules/**"
]
webRoot
This specifies the workspace absolute path to the webserver root. Used to resolve paths like /app.js to files on disk. Shorthand for a pathMapping for "/"
Default value:"${workspaceFolder}"
+
From e33707e5beb9c43818a4bfa4777a6ffa37824d8b Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Wed, 12 Nov 2025 10:46:28 +0000
Subject: [PATCH 3/4] Implement jsdbg command for debugging Node.js from any
terminal
Co-authored-by: hediet <2931520+hediet@users.noreply.github.com>
---
src/extension.ts | 2 ++
src/ui/jsdbgCommand.ts | 62 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 64 insertions(+)
create mode 100644 src/ui/jsdbgCommand.ts
diff --git a/src/extension.ts b/src/extension.ts
index 25d94eb97..254c7de82 100644
--- a/src/extension.ts
+++ b/src/extension.ts
@@ -25,6 +25,7 @@ import { debugNpmScript } from './ui/debugNpmScript';
import { DebugSessionTracker } from './ui/debugSessionTracker';
import { registerDebugTerminalUI } from './ui/debugTerminalUI';
import { ExtensionApiFactory } from './ui/extensionApi';
+import { registerJsdbgCommand } from './ui/jsdbgCommand';
import { attachProcess, pickProcess } from './ui/processPicker';
import { registerProfilingCommand } from './ui/profiling';
import { registerRequestCDPProxy } from './ui/requestCDPProxy';
@@ -104,6 +105,7 @@ export function activate(context: vscode.ExtensionContext): IExports {
registerCompanionBrowserLaunch(context);
registerCustomBreakpointsUI(context, debugSessionTracker);
registerDebugTerminalUI(context, services.get(DelegateLauncherFactory), services);
+ registerJsdbgCommand(context);
registerProfilingCommand(context, services);
registerAutoAttach(context, services.get(DelegateLauncherFactory), services);
registerRevealPage(context, debugSessionTracker);
diff --git a/src/ui/jsdbgCommand.ts b/src/ui/jsdbgCommand.ts
new file mode 100644
index 000000000..74a462e4f
--- /dev/null
+++ b/src/ui/jsdbgCommand.ts
@@ -0,0 +1,62 @@
+/*---------------------------------------------------------
+ * Copyright (C) Microsoft Corporation. All rights reserved.
+ *--------------------------------------------------------*/
+
+import * as vscode from 'vscode';
+import { Commands } from '../common/contributionUtils';
+
+/**
+ * Registers the jsdbg command terminal integration.
+ * This allows users to run `jsdbg node myScript.js` in any terminal
+ * to start a debug session, similar to the JavaScript Debug Terminal.
+ */
+export function registerJsdbgCommand(context: vscode.ExtensionContext) {
+ // Listen for command executions in all terminals
+ context.subscriptions.push(
+ vscode.window.onDidStartTerminalShellExecution(async event => {
+ const commandLine = event.execution.commandLine;
+ if (!commandLine || typeof commandLine.value !== 'string') {
+ return;
+ }
+
+ const command = commandLine.value.trim();
+
+ // Check if the command starts with jsdbg
+ if (command.startsWith('jsdbg ')) {
+ // Extract the actual command to debug
+ const actualCommand = command.substring('jsdbg '.length).trim();
+
+ if (!actualCommand) {
+ vscode.window.showErrorMessage('Usage: jsdbg ');
+ return;
+ }
+
+ // Get the current working directory from the terminal
+ const cwd = await getTerminalCwd(event.terminal);
+
+ // Create a JavaScript Debug Terminal with the command
+ await vscode.commands.executeCommand(
+ Commands.CreateDebuggerTerminal,
+ actualCommand,
+ cwd ? vscode.workspace.getWorkspaceFolder(vscode.Uri.file(cwd)) : undefined,
+ cwd ? { cwd } : undefined
+ );
+ }
+ })
+ );
+}
+
+/**
+ * Attempts to get the current working directory of a terminal.
+ */
+async function getTerminalCwd(terminal: vscode.Terminal): Promise {
+ // Try to get the CWD from shell integration
+ const shellIntegration = terminal.shellIntegration;
+ if (shellIntegration && shellIntegration.cwd) {
+ return shellIntegration.cwd.fsPath;
+ }
+
+ // Fallback to workspace folder
+ const folders = vscode.workspace.workspaceFolders;
+ return folders?.[0]?.uri.fsPath;
+}
From 115993b5c3389bb344cb11b4b60b0841352421bb Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Wed, 12 Nov 2025 10:48:31 +0000
Subject: [PATCH 4/4] Add documentation and improve jsdbg command handling
Co-authored-by: hediet <2931520+hediet@users.noreply.github.com>
---
CHANGELOG.md | 1 +
README.md | 10 +++++++++
src/ui/jsdbgCommand.ts | 46 ++++++++++++++++++++++++++++++------------
3 files changed, 44 insertions(+), 13 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6b20e12a0..b51fadd5a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,7 @@ This changelog records changes to stable releases since 1.50.2. "TBA" changes he
## 1.105 (September 2025)
+- feat: add `jsdbg` command for debugging Node.js from any terminal
- fix: slow sourcemap parsing for minified code ([#2265](https://github.com/microsoft/vscode-js-debug/issues/2265))
- fix: assorted race conditions on dwarf and breakpoint initialization
diff --git a/README.md b/README.md
index bc4adf5b0..b2666e18b 100644
--- a/README.md
+++ b/README.md
@@ -57,6 +57,16 @@ You can debug any Node.js process you run in the terminal with Auto Attach. If a
Once enabled, you can toggle Auto Attach by clicking the `Auto Attach: On/Off` button in the status bar on the bottom of your screen. You can also create a one-off terminal for debugging via the `Debug: Create JavaScript Debug Terminal` command.
+Alternatively, you can use the `jsdbg` command in any terminal (with shell integration enabled) to quickly debug a Node.js command without switching to a JavaScript Debug Terminal:
+
+```bash
+jsdbg node myScript.js
+jsdbg npm start
+jsdbg yarn test
+```
+
+When you run `jsdbg `, a new JavaScript Debug Terminal will be created with your command, allowing you to debug immediately.
+
### Profiling Support
You can capture and view performance profiles natively in VS Code, by clicking on the ⚪ button in the Call Stack view, or through the `Debug: Take Performance Profile` command. The profile information collected through VS Code is sourcemap-aware.
diff --git a/src/ui/jsdbgCommand.ts b/src/ui/jsdbgCommand.ts
index 74a462e4f..c356a7f5a 100644
--- a/src/ui/jsdbgCommand.ts
+++ b/src/ui/jsdbgCommand.ts
@@ -21,26 +21,46 @@ export function registerJsdbgCommand(context: vscode.ExtensionContext) {
const command = commandLine.value.trim();
- // Check if the command starts with jsdbg
- if (command.startsWith('jsdbg ')) {
+ // Check if the command starts with jsdbg (case-sensitive)
+ // Match "jsdbg " or "jsdbg" followed by whitespace
+ const jsdbgMatch = command.match(/^jsdbg\s+(.+)$/);
+ if (jsdbgMatch) {
// Extract the actual command to debug
- const actualCommand = command.substring('jsdbg '.length).trim();
+ const actualCommand = jsdbgMatch[1].trim();
if (!actualCommand) {
- vscode.window.showErrorMessage('Usage: jsdbg ');
+ vscode.window.showErrorMessage('Usage: jsdbg \n\nExample: jsdbg node myScript.js');
return;
}
- // Get the current working directory from the terminal
- const cwd = await getTerminalCwd(event.terminal);
+ try {
+ // Get the current working directory from the terminal
+ const cwd = await getTerminalCwd(event.terminal);
- // Create a JavaScript Debug Terminal with the command
- await vscode.commands.executeCommand(
- Commands.CreateDebuggerTerminal,
- actualCommand,
- cwd ? vscode.workspace.getWorkspaceFolder(vscode.Uri.file(cwd)) : undefined,
- cwd ? { cwd } : undefined
- );
+ // Create a JavaScript Debug Terminal with the command
+ await vscode.commands.executeCommand(
+ Commands.CreateDebuggerTerminal,
+ actualCommand,
+ cwd ? vscode.workspace.getWorkspaceFolder(vscode.Uri.file(cwd)) : undefined,
+ cwd ? { cwd } : undefined
+ );
+ } catch (error) {
+ vscode.window.showErrorMessage(
+ `Failed to create debug terminal: ${error instanceof Error ? error.message : String(error)}`
+ );
+ }
+ } else if (command === 'jsdbg') {
+ // Handle the case where jsdbg is run without arguments
+ vscode.window.showInformationMessage(
+ 'Usage: jsdbg \n\nExample: jsdbg node myScript.js',
+ 'Learn More'
+ ).then(selection => {
+ if (selection === 'Learn More') {
+ vscode.env.openExternal(vscode.Uri.parse(
+ 'https://code.visualstudio.com/docs/nodejs/nodejs-debugging'
+ ));
+ }
+ });
}
})
);