41d3d6b0f25eb3446f28f2f665168ca95ff2110d0e9cf0b4cfad8ba0dee702a20100788e14dd32d9fdbfbe4bc5eb03612905efd99613bcaf737068d2bd1be4 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /**
  2. * The `node:inspector` module provides an API for interacting with the V8
  3. * inspector.
  4. * @see [source](https://github.com/nodejs/node/blob/v24.x/lib/inspector.js)
  5. */
  6. declare module "inspector" {
  7. import EventEmitter = require("node:events");
  8. /**
  9. * The `inspector.Session` is used for dispatching messages to the V8 inspector
  10. * back-end and receiving message responses and notifications.
  11. */
  12. class Session extends EventEmitter {
  13. /**
  14. * Create a new instance of the inspector.Session class.
  15. * The inspector session needs to be connected through `session.connect()` before the messages can be dispatched to the inspector backend.
  16. */
  17. constructor();
  18. /**
  19. * Connects a session to the inspector back-end.
  20. */
  21. connect(): void;
  22. /**
  23. * Connects a session to the inspector back-end.
  24. * An exception will be thrown if this API was not called on a Worker thread.
  25. * @since v12.11.0
  26. */
  27. connectToMainThread(): void;
  28. /**
  29. * Immediately close the session. All pending message callbacks will be called with an error.
  30. * `session.connect()` will need to be called to be able to send messages again.
  31. * Reconnected session will lose all inspector state, such as enabled agents or configured breakpoints.
  32. */
  33. disconnect(): void;
  34. }
  35. /**
  36. * Activate inspector on host and port. Equivalent to `node --inspect=[[host:]port]`, but can be done programmatically after node has
  37. * started.
  38. *
  39. * If wait is `true`, will block until a client has connected to the inspect port
  40. * and flow control has been passed to the debugger client.
  41. *
  42. * See the [security warning](https://nodejs.org/docs/latest-v24.x/api/cli.html#warning-binding-inspector-to-a-public-ipport-combination-is-insecure)
  43. * regarding the `host` parameter usage.
  44. * @param port Port to listen on for inspector connections. Defaults to what was specified on the CLI.
  45. * @param host Host to listen on for inspector connections. Defaults to what was specified on the CLI.
  46. * @param wait Block until a client has connected. Defaults to what was specified on the CLI.
  47. * @returns Disposable that calls `inspector.close()`.
  48. */
  49. function open(port?: number, host?: string, wait?: boolean): Disposable;
  50. /**
  51. * Deactivate the inspector. Blocks until there are no active connections.
  52. */
  53. function close(): void;
  54. /**
  55. * Return the URL of the active inspector, or `undefined` if there is none.
  56. *
  57. * ```console
  58. * $ node --inspect -p 'inspector.url()'
  59. * Debugger listening on ws://127.0.0.1:9229/166e272e-7a30-4d09-97ce-f1c012b43c34
  60. * For help, see: https://nodejs.org/en/docs/inspector
  61. * ws://127.0.0.1:9229/166e272e-7a30-4d09-97ce-f1c012b43c34
  62. *
  63. * $ node --inspect=localhost:3000 -p 'inspector.url()'
  64. * Debugger listening on ws://localhost:3000/51cf8d0e-3c36-4c59-8efd-54519839e56a
  65. * For help, see: https://nodejs.org/en/docs/inspector
  66. * ws://localhost:3000/51cf8d0e-3c36-4c59-8efd-54519839e56a
  67. *
  68. * $ node -p 'inspector.url()'
  69. * undefined
  70. * ```
  71. */
  72. function url(): string | undefined;
  73. /**
  74. * Blocks until a client (existing or connected later) has sent `Runtime.runIfWaitingForDebugger` command.
  75. *
  76. * An exception will be thrown if there is no active inspector.
  77. * @since v12.7.0
  78. */
  79. function waitForDebugger(): void;
  80. // These methods are exposed by the V8 inspector console API (inspector/v8-console.h).
  81. // The method signatures differ from those of the Node.js console, and are deliberately
  82. // typed permissively.
  83. interface InspectorConsole {
  84. debug(...data: any[]): void;
  85. error(...data: any[]): void;
  86. info(...data: any[]): void;
  87. log(...data: any[]): void;
  88. warn(...data: any[]): void;
  89. dir(...data: any[]): void;
  90. dirxml(...data: any[]): void;
  91. table(...data: any[]): void;
  92. trace(...data: any[]): void;
  93. group(...data: any[]): void;
  94. groupCollapsed(...data: any[]): void;
  95. groupEnd(...data: any[]): void;
  96. clear(...data: any[]): void;
  97. count(label?: any): void;
  98. countReset(label?: any): void;
  99. assert(value?: any, ...data: any[]): void;
  100. profile(label?: any): void;
  101. profileEnd(label?: any): void;
  102. time(label?: any): void;
  103. timeLog(label?: any): void;
  104. timeStamp(label?: any): void;
  105. }
  106. /**
  107. * An object to send messages to the remote inspector console.
  108. * @since v11.0.0
  109. */
  110. const console: InspectorConsole;
  111. // DevTools protocol event broadcast methods
  112. namespace Network {
  113. /**
  114. * This feature is only available with the `--experimental-network-inspection` flag enabled.
  115. *
  116. * Broadcasts the `Network.requestWillBeSent` event to connected frontends. This event indicates that
  117. * the application is about to send an HTTP request.
  118. * @since v22.6.0
  119. */
  120. function requestWillBeSent(params: RequestWillBeSentEventDataType): void;
  121. /**
  122. * This feature is only available with the `--experimental-network-inspection` flag enabled.
  123. *
  124. * Broadcasts the `Network.dataReceived` event to connected frontends, or buffers the data if
  125. * `Network.streamResourceContent` command was not invoked for the given request yet.
  126. *
  127. * Also enables `Network.getResponseBody` command to retrieve the response data.
  128. * @since v24.2.0
  129. */
  130. function dataReceived(params: DataReceivedEventDataType): void;
  131. /**
  132. * This feature is only available with the `--experimental-network-inspection` flag enabled.
  133. *
  134. * Enables `Network.getRequestPostData` command to retrieve the request data.
  135. * @since v24.3.0
  136. */
  137. function dataSent(params: unknown): void;
  138. /**
  139. * This feature is only available with the `--experimental-network-inspection` flag enabled.
  140. *
  141. * Broadcasts the `Network.responseReceived` event to connected frontends. This event indicates that
  142. * HTTP response is available.
  143. * @since v22.6.0
  144. */
  145. function responseReceived(params: ResponseReceivedEventDataType): void;
  146. /**
  147. * This feature is only available with the `--experimental-network-inspection` flag enabled.
  148. *
  149. * Broadcasts the `Network.loadingFinished` event to connected frontends. This event indicates that
  150. * HTTP request has finished loading.
  151. * @since v22.6.0
  152. */
  153. function loadingFinished(params: LoadingFinishedEventDataType): void;
  154. /**
  155. * This feature is only available with the `--experimental-network-inspection` flag enabled.
  156. *
  157. * Broadcasts the `Network.loadingFailed` event to connected frontends. This event indicates that
  158. * HTTP request has failed to load.
  159. * @since v22.7.0
  160. */
  161. function loadingFailed(params: LoadingFailedEventDataType): void;
  162. }
  163. namespace NetworkResources {
  164. /**
  165. * This feature is only available with the `--experimental-inspector-network-resource` flag enabled.
  166. *
  167. * The inspector.NetworkResources.put method is used to provide a response for a loadNetworkResource
  168. * request issued via the Chrome DevTools Protocol (CDP).
  169. * This is typically triggered when a source map is specified by URL, and a DevTools frontend—such as
  170. * Chrome—requests the resource to retrieve the source map.
  171. *
  172. * This method allows developers to predefine the resource content to be served in response to such CDP requests.
  173. *
  174. * ```js
  175. * const inspector = require('node:inspector');
  176. * // By preemptively calling put to register the resource, a source map can be resolved when
  177. * // a loadNetworkResource request is made from the frontend.
  178. * async function setNetworkResources() {
  179. * const mapUrl = 'http://localhost:3000/dist/app.js.map';
  180. * const tsUrl = 'http://localhost:3000/src/app.ts';
  181. * const distAppJsMap = await fetch(mapUrl).then((res) => res.text());
  182. * const srcAppTs = await fetch(tsUrl).then((res) => res.text());
  183. * inspector.NetworkResources.put(mapUrl, distAppJsMap);
  184. * inspector.NetworkResources.put(tsUrl, srcAppTs);
  185. * };
  186. * setNetworkResources().then(() => {
  187. * require('./dist/app');
  188. * });
  189. * ```
  190. *
  191. * For more details, see the official CDP documentation: [Network.loadNetworkResource](https://chromedevtools.github.io/devtools-protocol/tot/Network/#method-loadNetworkResource)
  192. * @since v24.5.0
  193. * @experimental
  194. */
  195. function put(url: string, data: string): void;
  196. }
  197. }
  198. /**
  199. * The `node:inspector` module provides an API for interacting with the V8
  200. * inspector.
  201. */
  202. declare module "node:inspector" {
  203. export * from "inspector";
  204. }
  205. /**
  206. * The `node:inspector/promises` module provides an API for interacting with the V8
  207. * inspector.
  208. * @see [source](https://github.com/nodejs/node/blob/v24.x/lib/inspector/promises.js)
  209. * @since v19.0.0
  210. */
  211. declare module "inspector/promises" {
  212. import EventEmitter = require("node:events");
  213. export { close, console, NetworkResources, open, url, waitForDebugger } from "inspector";
  214. /**
  215. * The `inspector.Session` is used for dispatching messages to the V8 inspector
  216. * back-end and receiving message responses and notifications.
  217. * @since v19.0.0
  218. */
  219. export class Session extends EventEmitter {
  220. /**
  221. * Create a new instance of the inspector.Session class.
  222. * The inspector session needs to be connected through `session.connect()` before the messages can be dispatched to the inspector backend.
  223. */
  224. constructor();
  225. /**
  226. * Connects a session to the inspector back-end.
  227. */
  228. connect(): void;
  229. /**
  230. * Connects a session to the inspector back-end.
  231. * An exception will be thrown if this API was not called on a Worker thread.
  232. * @since v12.11.0
  233. */
  234. connectToMainThread(): void;
  235. /**
  236. * Immediately close the session. All pending message callbacks will be called with an error.
  237. * `session.connect()` will need to be called to be able to send messages again.
  238. * Reconnected session will lose all inspector state, such as enabled agents or configured breakpoints.
  239. */
  240. disconnect(): void;
  241. }
  242. }
  243. /**
  244. * The `node:inspector/promises` module provides an API for interacting with the V8
  245. * inspector.
  246. * @since v19.0.0
  247. */
  248. declare module "node:inspector/promises" {
  249. export * from "inspector/promises";
  250. }