跳到正文
Skillpedia
通用编程394k · #67

node-inspect-debugger

它能做什么

它指导 AI 智能体使用 Node.js 检查器暂停代码、查看变量,并获取内存和 CPU 分析数据。它适合需要找出普通日志无法显示的错误的开发者。

适用场景

  • ✓Node.js 程序卡住、崩溃,或每次运行表现都不同的时候。
  • ✓你怀疑某个 Node.js 程序的内存占用越来越高的时候。
  • ✓你想在某一行暂停代码,并查看其变量值的时候。

技能链接

https://github.com/openclaw/openclaw/blob/main/skills/node-inspect-debugger/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/openclaw/openclaw/blob/main/skills/node-inspect-debugger/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“我的 Node.js 脚本运行几秒后就卡住了。请帮我在它卡住时暂停,看看是什么地方停住了。”

每周 5 个新技能,1 分钟读完。

工作原理

技能使用检查器启动程序,设置断点,并检查其状态。遇到较难的情况时,它会获取堆或 CPU 分析数据,并在得出结论前进行检查。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Node Inspect Debugger

Use for Node.js debugging that needs inspector access: hidden locals, async hangs, flaky tests, child processes, startup races, memory growth, or CPU hot paths.

Default to node inspect first. Use Chrome DevTools Protocol only when you need scripted breakpoints, automated state capture, heap snapshots, or CPU profiles.

Quick start

  • Pause on entry: node inspect path/to/script.js
  • TypeScript: node --inspect-brk --import tsx path/to/script.ts
  • Existing PID: kill -SIGUSR1 <pid> then node inspect -p <pid>
  • Inspect target list: curl -s http://127.0.0.1:9229/json/list | jq
  • OpenClaw CLI path: node --inspect-brk openclaw.mjs ...
  • OpenClaw test path: OPENCLAW_VITEST_MAX_WORKERS=1 node --inspect-brk scripts/run-vitest.mjs <file>

Debugger REPL

  • Continue/step: cont, next, step, out, pause
  • Breakpoints: sb('file.js', 42), sb(42), sb('functionName'), breakpoints, cb('file.js', 42)
  • Inspect: bt, list(8), watch('expr'), exec expr
  • Current scope: repl, then evaluate locals directly; Ctrl+C exits repl mode.
  • Exit safely: cont before quitting if the process should continue; otherwise kill.

OpenClaw tips

  • Prefer 127.0.0.1 inspector binds. Do not expose --inspect=0.0.0.0 unless the network is isolated.
  • For Vitest, debug one file with one worker. Avoid worker pools while stepping.
  • For TS source breakpoints, use --enable-source-maps when useful; node inspect can still show emitted paths.
  • For child processes, NODE_OPTIONS=--inspect-brk can propagate the inspector, but each child needs its own port.
  • For long-lived gateway or dev processes, attach by PID after confirming the target with /json/list.

Programmatic CDP

Install tooling outside the repo unless the project already depends on it:

mkdir -p /tmp/cdp-tools
npm --prefix /tmp/cdp-tools i chrome-remote-interface
NODE_PATH=/tmp/cdp-tools/node_modules node /tmp/cdp-debug.cjs

Minimal driver:

const CDP = require("chrome-remote-interface");

(async () => {
  const client = await CDP({ port: 9229 });
  const { Debugger, Runtime } = client;

  Debugger.paused(async ({ callFrames, reason }) => {
    const top = callFrames[0];
    console.log("paused", reason, top.url, top.location.lineNumber + 1);
    const { result } = await Debugger.evaluateOnCallFrame({
      callFrameId: top.callFrameId,
      expression: "JSON.stringify({ pid: process.pid })",
    });
    console.log(result.value ?? result.description);
    await Debugger.resume();
  });

  await Runtime.enable();
  await Debugger.enable();
  await Debugger.setBreakpointByUrl({ urlRegex: ".*target\\.js$", lineNumber: 41 });
  await Runtime.runIfWaitingForDebugger();
})();

Profiles

  • CPU: enable Profiler, start, wait, stop, write /tmp/profile.cpuprofile, open in Chrome DevTools.
  • Heap: enable HeapProfiler, collect addHeapSnapshotChunk, call takeHeapSnapshot, write /tmp/heap.heapsnapshot.

Pitfalls

  • --inspect does not pause; use --inspect-brk when setup must happen before code runs.
  • Default port is 9229; use --inspect=0 or a unique port for parallel targets.
  • If a breakpoint misses, confirm file path, source map behavior, and whether execution already passed the line.
  • If the process appears frozen after detaching, it may still be paused in the debugger.
常见问题

我需要知道调试器的命令吗?

不需要。技能会替你运行常用命令,并解释每一步显示的内容。

在网络上开启调试器安全吗?

除非网络是隔离的,否则请把检查器绑定到 127.0.0.1,因为对外暴露可能有风险。

什么是堆快照?

它是程序在某一时刻内存中所保存内容的快照,用于找出从未被释放的内存。

详情

作者的原始描述

Debug Node.js with node inspect, --inspect, breakpoints, CDP, heap, and CPU profiles.

repo: openclaw/openclaw

热度

GitHub 星标
394k
排名
#67
许可证
MIT
更新时间
2026/11/2

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能