与 DevTools 集成


【Integration with DevTools】

稳定性: 1.1 - 处于活跃开发中

node:inspector 模块提供了一个 API,用于与支持 Chrome 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',
  },
});