与 DevTools 集成


¥Integration with DevTools

node:inspector 模块提供了一个 API,用于与支持 Chrome DevTools 协议的 devtools 集成。连接到正在运行的 Node.js 实例的 DevTools 前端可以捕获从实例触发的协议事件并相应地显示它们以方便调试。以下方法将协议事件广播到所有连接的前端。传递给方法的 params 可以是可选的,具体取决于协议。

¥The node:inspector module provides an API for integrating with devtools that support Chrome DevTools Protocol. DevTools frontends connected to a running Node.js instance can capture protocol events emitted from the instance and display them accordingly to facilitate debugging. The following methods broadcast a protocol event to all connected frontends. The params passed to the methods can be optional, depending on the protocol.

// The `Network.requestWillBeSent` event will be fired.
inspector.Network.requestWillBeSent({
  requestId: 'request-id-1',
  timestamp: Date.now() / 1000,
  wallTime: Date.now(),
  request: {
    url: 'https://nodejs.cn/en',
    method: 'GET',
  },
});