2016-12-12 17:08:31 -08:00
|
|
|
# Inspector
|
|
|
|
|
2017-11-04 09:08:46 +01:00
|
|
|
<!--introduced_in=v8.0.0-->
|
|
|
|
|
2021-03-14 08:48:34 +05:30
|
|
|
> Stability: 2 - Stable
|
2016-12-12 17:08:31 -08:00
|
|
|
|
2020-06-22 13:56:08 -04:00
|
|
|
<!-- source_link=lib/inspector.js -->
|
|
|
|
|
2022-04-20 10:23:41 +02:00
|
|
|
The `node:inspector` module provides an API for interacting with the V8
|
|
|
|
inspector.
|
2016-12-12 17:08:31 -08:00
|
|
|
|
|
|
|
It can be accessed using:
|
|
|
|
|
2022-10-13 20:12:05 -03:00
|
|
|
```mjs
|
|
|
|
import * as inspector from 'node:inspector/promises';
|
|
|
|
```
|
|
|
|
|
|
|
|
```cjs
|
|
|
|
const inspector = require('node:inspector/promises');
|
|
|
|
```
|
|
|
|
|
|
|
|
or
|
|
|
|
|
|
|
|
```mjs
|
|
|
|
import * as inspector from 'node:inspector';
|
|
|
|
```
|
|
|
|
|
|
|
|
```cjs
|
2022-04-20 10:23:41 +02:00
|
|
|
const inspector = require('node:inspector');
|
2016-12-12 17:08:31 -08:00
|
|
|
```
|
|
|
|
|
2022-10-13 20:12:05 -03:00
|
|
|
## Promises API
|
|
|
|
|
2022-09-14 01:20:01 +08:00
|
|
|
<!-- YAML
|
2022-09-13 12:53:52 -03:00
|
|
|
added: v19.0.0
|
2022-09-14 01:20:01 +08:00
|
|
|
-->
|
|
|
|
|
2025-02-12 19:25:09 +01:00
|
|
|
> Stability: 1 - Experimental
|
|
|
|
|
2022-10-13 20:12:05 -03:00
|
|
|
### Class: `inspector.Session`
|
2018-07-08 16:58:40 +03:00
|
|
|
|
2022-10-13 20:12:05 -03:00
|
|
|
* Extends: {EventEmitter}
|
2018-07-08 16:58:40 +03:00
|
|
|
|
2022-10-13 20:12:05 -03:00
|
|
|
The `inspector.Session` is used for dispatching messages to the V8 inspector
|
|
|
|
back-end and receiving message responses and notifications.
|
|
|
|
|
|
|
|
#### `new inspector.Session()`
|
|
|
|
|
|
|
|
<!-- YAML
|
|
|
|
added: v8.0.0
|
|
|
|
-->
|
|
|
|
|
|
|
|
Create a new instance of the `inspector.Session` class. The inspector session
|
|
|
|
needs to be connected through [`session.connect()`][] before the messages
|
|
|
|
can be dispatched to the inspector backend.
|
|
|
|
|
2023-04-23 17:04:08 +03:30
|
|
|
When using `Session`, the object outputted by the console API will not be
|
2023-04-21 00:16:11 +08:00
|
|
|
released, unless we performed manually `Runtime.DiscardConsoleEntries`
|
|
|
|
command.
|
|
|
|
|
2022-10-13 20:12:05 -03:00
|
|
|
#### Event: `'inspectorNotification'`
|
|
|
|
|
|
|
|
<!-- YAML
|
|
|
|
added: v8.0.0
|
|
|
|
-->
|
|
|
|
|
|
|
|
* {Object} The notification message object
|
|
|
|
|
|
|
|
Emitted when any notification from the V8 Inspector is received.
|
2018-07-08 16:58:40 +03:00
|
|
|
|
|
|
|
```js
|
2022-10-13 20:12:05 -03:00
|
|
|
session.on('inspectorNotification', (message) => console.log(message.method));
|
|
|
|
// Debugger.paused
|
|
|
|
// Debugger.resumed
|
2018-07-08 16:58:40 +03:00
|
|
|
```
|
|
|
|
|
2024-01-18 14:30:33 +08:00
|
|
|
> **Caveat** Breakpoints with same-thread session is not recommended, see
|
|
|
|
> [support of breakpoints][].
|
|
|
|
|
2022-10-13 20:12:05 -03:00
|
|
|
It is also possible to subscribe only to notifications with specific method:
|
2018-07-08 16:58:40 +03:00
|
|
|
|
2022-10-13 20:12:05 -03:00
|
|
|
#### Event: `<inspector-protocol-method>`;
|
2017-05-25 19:00:24 -07:00
|
|
|
|
2022-10-13 20:12:05 -03:00
|
|
|
<!-- YAML
|
|
|
|
added: v8.0.0
|
|
|
|
-->
|
2017-05-25 19:00:24 -07:00
|
|
|
|
2022-10-13 20:12:05 -03:00
|
|
|
* {Object} The notification message object
|
2017-05-25 19:00:24 -07:00
|
|
|
|
2022-10-13 20:12:05 -03:00
|
|
|
Emitted when an inspector notification is received that has its method field set
|
|
|
|
to the `<inspector-protocol-method>` value.
|
2017-05-25 19:00:24 -07:00
|
|
|
|
2022-10-13 20:12:05 -03:00
|
|
|
The following snippet installs a listener on the [`'Debugger.paused'`][]
|
|
|
|
event, and prints the reason for program suspension whenever program
|
|
|
|
execution is suspended (through breakpoints, for example):
|
2018-10-13 19:40:44 +03:00
|
|
|
|
2022-10-13 20:12:05 -03:00
|
|
|
```js
|
|
|
|
session.on('Debugger.paused', ({ params }) => {
|
|
|
|
console.log(params.hitBreakpoints);
|
|
|
|
});
|
|
|
|
// [ '/the/file/that/has/the/breakpoint.js:11:0' ]
|
|
|
|
```
|
2017-05-25 19:00:24 -07:00
|
|
|
|
2024-01-18 14:30:33 +08:00
|
|
|
> **Caveat** Breakpoints with same-thread session is not recommended, see
|
|
|
|
> [support of breakpoints][].
|
|
|
|
|
2022-10-13 20:12:05 -03:00
|
|
|
#### `session.connect()`
|
2018-04-11 21:07:14 +03:00
|
|
|
|
2022-10-13 20:12:05 -03:00
|
|
|
<!-- YAML
|
|
|
|
added: v8.0.0
|
|
|
|
-->
|
2017-05-25 19:00:24 -07:00
|
|
|
|
2022-10-13 20:12:05 -03:00
|
|
|
Connects a session to the inspector back-end.
|
2019-09-08 13:49:25 -05:00
|
|
|
|
2022-10-13 20:12:05 -03:00
|
|
|
#### `session.connectToMainThread()`
|
2019-09-08 13:49:25 -05:00
|
|
|
|
2022-10-13 20:12:05 -03:00
|
|
|
<!-- YAML
|
|
|
|
added: v12.11.0
|
|
|
|
-->
|
2019-09-08 13:49:25 -05:00
|
|
|
|
2022-10-13 20:12:05 -03:00
|
|
|
Connects a session to the main thread inspector back-end. An exception will
|
|
|
|
be thrown if this API was not called on a Worker thread.
|
|
|
|
|
|
|
|
#### `session.disconnect()`
|
2021-10-10 21:55:04 -07:00
|
|
|
|
2019-06-25 15:28:56 -07:00
|
|
|
<!-- YAML
|
2022-10-13 20:12:05 -03:00
|
|
|
added: v8.0.0
|
2019-06-25 15:28:56 -07:00
|
|
|
-->
|
|
|
|
|
2022-10-13 20:12:05 -03:00
|
|
|
Immediately close the session. All pending message callbacks will be called
|
|
|
|
with an error. [`session.connect()`][] will need to be called to be able to send
|
|
|
|
messages again. Reconnected session will lose all inspector state, such as
|
|
|
|
enabled agents or configured breakpoints.
|
2019-06-25 15:28:56 -07:00
|
|
|
|
2022-10-13 20:12:05 -03:00
|
|
|
#### `session.post(method[, params])`
|
2019-06-25 15:28:56 -07:00
|
|
|
|
2022-10-13 20:12:05 -03:00
|
|
|
<!-- YAML
|
2022-09-13 12:53:52 -03:00
|
|
|
added: v19.0.0
|
2022-10-13 20:12:05 -03:00
|
|
|
-->
|
|
|
|
|
|
|
|
* `method` {string}
|
|
|
|
* `params` {Object}
|
|
|
|
* Returns: {Promise}
|
|
|
|
|
|
|
|
Posts a message to the inspector back-end.
|
|
|
|
|
|
|
|
```mjs
|
|
|
|
import { Session } from 'node:inspector/promises';
|
|
|
|
try {
|
|
|
|
const session = new Session();
|
|
|
|
session.connect();
|
|
|
|
const result = await session.post('Runtime.evaluate', { expression: '2 + 2' });
|
|
|
|
console.log(result);
|
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
|
|
|
}
|
2023-01-07 08:49:36 +09:00
|
|
|
// Output: { result: { type: 'number', value: 4, description: '4' } }
|
2022-10-13 20:12:05 -03:00
|
|
|
```
|
|
|
|
|
|
|
|
The latest version of the V8 inspector protocol is published on the
|
|
|
|
[Chrome DevTools Protocol Viewer][].
|
|
|
|
|
|
|
|
Node.js inspector supports all the Chrome DevTools Protocol domains declared
|
|
|
|
by V8. Chrome DevTools Protocol domain provides an interface for interacting
|
|
|
|
with one of the runtime agents used to inspect the application state and listen
|
|
|
|
to the run-time events.
|
|
|
|
|
|
|
|
#### Example usage
|
|
|
|
|
|
|
|
Apart from the debugger, various V8 Profilers are available through the DevTools
|
|
|
|
protocol.
|
|
|
|
|
|
|
|
##### CPU profiler
|
|
|
|
|
|
|
|
Here's an example showing how to use the [CPU Profiler][]:
|
|
|
|
|
|
|
|
```mjs
|
|
|
|
import { Session } from 'node:inspector/promises';
|
|
|
|
import fs from 'node:fs';
|
|
|
|
const session = new Session();
|
|
|
|
session.connect();
|
|
|
|
|
|
|
|
await session.post('Profiler.enable');
|
|
|
|
await session.post('Profiler.start');
|
|
|
|
// Invoke business logic under measurement here...
|
|
|
|
|
|
|
|
// some time later...
|
|
|
|
const { profile } = await session.post('Profiler.stop');
|
|
|
|
|
|
|
|
// Write profile to disk, upload, etc.
|
|
|
|
fs.writeFileSync('./profile.cpuprofile', JSON.stringify(profile));
|
|
|
|
```
|
|
|
|
|
|
|
|
##### Heap profiler
|
|
|
|
|
|
|
|
Here's an example showing how to use the [Heap Profiler][]:
|
|
|
|
|
|
|
|
```mjs
|
|
|
|
import { Session } from 'node:inspector/promises';
|
|
|
|
import fs from 'node:fs';
|
|
|
|
const session = new Session();
|
|
|
|
|
|
|
|
const fd = fs.openSync('profile.heapsnapshot', 'w');
|
|
|
|
|
|
|
|
session.connect();
|
|
|
|
|
|
|
|
session.on('HeapProfiler.addHeapSnapshotChunk', (m) => {
|
|
|
|
fs.writeSync(fd, m.params.chunk);
|
|
|
|
});
|
|
|
|
|
|
|
|
const result = await session.post('HeapProfiler.takeHeapSnapshot', null);
|
|
|
|
console.log('HeapProfiler.takeHeapSnapshot done:', result);
|
|
|
|
session.disconnect();
|
|
|
|
fs.closeSync(fd);
|
|
|
|
```
|
|
|
|
|
|
|
|
## Callback API
|
|
|
|
|
|
|
|
### Class: `inspector.Session`
|
2016-12-12 17:08:31 -08:00
|
|
|
|
2019-08-23 22:02:23 -07:00
|
|
|
* Extends: {EventEmitter}
|
|
|
|
|
2016-12-12 17:08:31 -08:00
|
|
|
The `inspector.Session` is used for dispatching messages to the V8 inspector
|
|
|
|
back-end and receiving message responses and notifications.
|
|
|
|
|
2022-10-13 20:12:05 -03:00
|
|
|
#### `new inspector.Session()`
|
2021-10-10 21:55:04 -07:00
|
|
|
|
2016-12-12 17:08:31 -08:00
|
|
|
<!-- YAML
|
2017-03-15 20:26:14 -07:00
|
|
|
added: v8.0.0
|
2016-12-12 17:08:31 -08:00
|
|
|
-->
|
|
|
|
|
|
|
|
Create a new instance of the `inspector.Session` class. The inspector session
|
|
|
|
needs to be connected through [`session.connect()`][] before the messages
|
|
|
|
can be dispatched to the inspector backend.
|
|
|
|
|
2023-04-23 17:04:08 +03:30
|
|
|
When using `Session`, the object outputted by the console API will not be
|
2023-04-21 00:16:11 +08:00
|
|
|
released, unless we performed manually `Runtime.DiscardConsoleEntries`
|
|
|
|
command.
|
|
|
|
|
2022-10-13 20:12:05 -03:00
|
|
|
#### Event: `'inspectorNotification'`
|
2021-10-10 21:55:04 -07:00
|
|
|
|
2016-12-12 17:08:31 -08:00
|
|
|
<!-- YAML
|
2017-03-15 20:26:14 -07:00
|
|
|
added: v8.0.0
|
2016-12-12 17:08:31 -08:00
|
|
|
-->
|
|
|
|
|
|
|
|
* {Object} The notification message object
|
|
|
|
|
|
|
|
Emitted when any notification from the V8 Inspector is received.
|
|
|
|
|
|
|
|
```js
|
|
|
|
session.on('inspectorNotification', (message) => console.log(message.method));
|
|
|
|
// Debugger.paused
|
|
|
|
// Debugger.resumed
|
|
|
|
```
|
|
|
|
|
2024-01-18 14:30:33 +08:00
|
|
|
> **Caveat** Breakpoints with same-thread session is not recommended, see
|
|
|
|
> [support of breakpoints][].
|
|
|
|
|
2016-12-12 17:08:31 -08:00
|
|
|
It is also possible to subscribe only to notifications with specific method:
|
|
|
|
|
2022-10-13 20:12:05 -03:00
|
|
|
#### Event: `<inspector-protocol-method>`;
|
2021-10-10 21:55:04 -07:00
|
|
|
|
2016-12-12 17:08:31 -08:00
|
|
|
<!-- YAML
|
2017-03-15 20:26:14 -07:00
|
|
|
added: v8.0.0
|
2016-12-12 17:08:31 -08:00
|
|
|
-->
|
|
|
|
|
|
|
|
* {Object} The notification message object
|
|
|
|
|
|
|
|
Emitted when an inspector notification is received that has its method field set
|
|
|
|
to the `<inspector-protocol-method>` value.
|
|
|
|
|
2018-04-09 19:30:22 +03:00
|
|
|
The following snippet installs a listener on the [`'Debugger.paused'`][]
|
2016-12-12 17:08:31 -08:00
|
|
|
event, and prints the reason for program suspension whenever program
|
|
|
|
execution is suspended (through breakpoints, for example):
|
|
|
|
|
|
|
|
```js
|
2017-06-01 02:07:25 +03:00
|
|
|
session.on('Debugger.paused', ({ params }) => {
|
|
|
|
console.log(params.hitBreakpoints);
|
|
|
|
});
|
2017-10-17 22:26:34 -04:00
|
|
|
// [ '/the/file/that/has/the/breakpoint.js:11:0' ]
|
2016-12-12 17:08:31 -08:00
|
|
|
```
|
|
|
|
|
2024-01-18 14:30:33 +08:00
|
|
|
> **Caveat** Breakpoints with same-thread session is not recommended, see
|
|
|
|
> [support of breakpoints][].
|
|
|
|
|
2022-10-13 20:12:05 -03:00
|
|
|
#### `session.connect()`
|
2021-10-10 21:55:04 -07:00
|
|
|
|
2016-12-12 17:08:31 -08:00
|
|
|
<!-- YAML
|
2017-03-15 20:26:14 -07:00
|
|
|
added: v8.0.0
|
2016-12-12 17:08:31 -08:00
|
|
|
-->
|
|
|
|
|
2019-07-26 10:40:54 -07:00
|
|
|
Connects a session to the inspector back-end.
|
|
|
|
|
2022-10-13 20:12:05 -03:00
|
|
|
#### `session.connectToMainThread()`
|
2021-10-10 21:55:04 -07:00
|
|
|
|
2019-07-26 10:40:54 -07:00
|
|
|
<!-- YAML
|
2019-09-25 00:45:45 +02:00
|
|
|
added: v12.11.0
|
2019-07-26 10:40:54 -07:00
|
|
|
-->
|
|
|
|
|
|
|
|
Connects a session to the main thread inspector back-end. An exception will
|
|
|
|
be thrown if this API was not called on a Worker thread.
|
2016-12-12 17:08:31 -08:00
|
|
|
|
2022-10-13 20:12:05 -03:00
|
|
|
#### `session.disconnect()`
|
2021-10-10 21:55:04 -07:00
|
|
|
|
2018-07-08 16:58:40 +03:00
|
|
|
<!-- YAML
|
|
|
|
added: v8.0.0
|
|
|
|
-->
|
|
|
|
|
|
|
|
Immediately close the session. All pending message callbacks will be called
|
2019-10-02 00:31:57 -04:00
|
|
|
with an error. [`session.connect()`][] will need to be called to be able to send
|
2018-07-08 16:58:40 +03:00
|
|
|
messages again. Reconnected session will lose all inspector state, such as
|
|
|
|
enabled agents or configured breakpoints.
|
|
|
|
|
2022-10-13 20:12:05 -03:00
|
|
|
#### `session.post(method[, params][, callback])`
|
2021-10-10 21:55:04 -07:00
|
|
|
|
2016-12-12 17:08:31 -08:00
|
|
|
<!-- YAML
|
2017-03-15 20:26:14 -07:00
|
|
|
added: v8.0.0
|
2022-01-24 19:39:16 +03:30
|
|
|
changes:
|
2022-04-19, Version 18.0.0 (Current)
Notable Changes:
Deprecations and Removals:
- (SEMVER-MAJOR) fs: runtime deprecate string coercion in `fs.write`,
`fs.writeFileSync`
(Livia Medeiros) (https://github.com/nodejs/node/pull/42607)
- (SEMVER-MAJOR) dns: remove `dns.lookup` and `dnsPromises.lookup`
options type coercion
(Antoine du Hamel) (https://github.com/nodejs/node/pull/41431)
- (SEMVER-MAJOR) process: runtime deprecate multipleResolves
(Benjamin Gruenbaum) (https://github.com/nodejs/node/pull/41896)
- (SEMVER-MAJOR) stream: remove thenable support (Robert Nagy)
(https://github.com/nodejs/node/pull/40773)
- (SEMVER-MAJOR) tls: move tls.parseCertString to end-of-life
(Tobias Nießen) (https://github.com/nodejs/node/pull/41479)
fetch (experimental):
An experimental fetch API is available on the global scope by default.
The implementation is based upon https://undici.nodejs.org/#/,
an HTTP/1.1 client written for Node.js by contributors to the project.
Through this addition, the following globals are made available: `fetch`
, `FormData`, `Headers`, `Request`, `Response`.
Disable this API with the `--no-experimental-fetch` command-line flag.
Contributed by Michaël Zasso in https://github.com/nodejs/node/pull/41811.
HTTP Timeouts:
`server.headersTimeout`, which limits the amount of time the parser will
wait to receive the complete HTTP headers, is now set to `60000` (60
seconds) by default.
`server.requestTimeout`, which sets the timeout value in milliseconds
for receiving the entire request from the client, is now set to `300000`
(5 minutes) by default.
If these timeouts expire, the server responds with status 408 without
forwarding the request to the request listener and then closes the
connection.
Both timeouts must be set to a non-zero value to protect against
potential Denial-of-Service attacks in case the server is deployed
without a reverse proxy in front.
Contributed by Paolo Insogna in https://github.com/nodejs/node/pull/41263.
Test Runner module (experimental):
The `node:test` module facilitates the creation of JavaScript tests that
report results in TAP format. This module is only available under the
`node:` scheme.
Contributed by Colin Ihrig in https://github.com/nodejs/node/pull/42325.
Toolchain and Compiler Upgrades:
- Prebuilt binaries for Linux are now built on Red Hat Enterprise Linux
(RHEL) 8 and are compatible with Linux distributions based on glibc
2.28 or later, for example, Debian 10, RHEL 8, Ubuntu 20.04.
- Prebuilt binaries for macOS now require macOS 10.15 or later.
- For AIX the minimum supported architecture has been raised from Power
7 to Power 8.
Prebuilt binaries for 32-bit Windows will initially not be available due
to issues building the V8 dependency in Node.js. We hope to restore
32-bit Windows binaries for Node.js 18 with a future V8 update.
Node.js does not support running on operating systems that are no longer
supported by their vendor. For operating systems where their vendor has
planned to end support earlier than April 2025, such as Windows 8.1
(January 2023) and Windows Server 2012 R2 (October 2023), support for
Node.js 18 will end at the earlier date.
Full details about the supported toolchains and compilers are documented
in the Node.js `BUILDING.md` file.
Contributed by Richard Lau in https://github.com/nodejs/node/pull/42292,
https://github.com/nodejs/node/pull/42604 and https://github.com/nodejs/node/pull/42659
, and Michaël Zasso in https://github.com/nodejs/node/pull/42105 and
https://github.com/nodejs/node/pull/42666.
V8 10.1:
The V8 engine is updated to version 10.1, which is part of Chromium 101.
Compared to the version included in Node.js 17.9.0, the following new
features are included:
- The `findLast` and `findLastIndex` array methods.
- Improvements to the `Intl.Locale` API.
- The `Intl.supportedValuesOf` function.
- Improved performance of class fields and private class methods (the
initialization of them is now as fast as ordinary property stores).
The data format returned by the serialization API (`v8.serialize(value)`)
has changed, and cannot be deserialized by earlier versions of Node.js.
On the other hand, it is still possible to deserialize the previous
format, as the API is backwards-compatible.
Contributed by Michaël Zasso in https://github.com/nodejs/node/pull/42657.
Web Streams API (experimental):
Node.js now exposes the experimental implementation of the Web Streams
API on the global scope. This means the following APIs are now globally
available:
- `ReadableStream`, `ReadableStreamDefaultReader`,
`ReadableStreamBYOBReader`, `ReadableStreamBYOBRequest`,
`ReadableByteStreamController`, `ReadableStreamDefaultController`,
`TransformStream`, `TransformStreamDefaultController`, `WritableStream`,
`WritableStreamDefaultWriter`, `WritableStreamDefaultController`,
`ByteLengthQueuingStrategy`, `CountQueuingStrategy`, `TextEncoderStream`,
`TextDecoderStream`, `CompressionStream`, `DecompressionStream`.
Contributed James Snell in https://github.com/nodejs/node/pull/39062,
and Antoine du Hamel in https://github.com/nodejs/node/pull/42225.
Other Notable Changes:
- (SEMVER-MAJOR) buffer: expose Blob as a global
(James M Snell) (https://github.com/nodejs/node/pull/41270)
- (SEMVER-MAJOR) child\_process: improve argument validation
(Rich Trott) (https://github.com/nodejs/node/pull/41305)
- doc: add RafaelGSS to collaborators
(RafaelGSS) (https://github.com/nodejs/node/pull/42718)
- (SEMVER-MAJOR) http: make TCP noDelay enabled by default
(Paolo Insogna) (https://github.com/nodejs/node/pull/42163)
- (SEMVER-MAJOR) net: make `server.address()` return an integer for
`family`
(Antoine du Hamel) (https://github.com/nodejs/node/pull/41431)
- (SEMVER-MAJOR) worker: expose BroadcastChannel as a global
(James M Snell) (https://github.com/nodejs/node/pull/41271)
- (SEMVER-MAJOR) worker: graduate BroadcastChannel to supported
(James M Snell) (https://github.com/nodejs/node/pull/41271)
Semver-Major Commits:
- (SEMVER-MAJOR) assert,util: compare RegExp.lastIndex while using deep
equal checks
(Ruben Bridgewater) (https://github.com/nodejs/node/pull/41020)
- (SEMVER-MAJOR) buffer: refactor `byteLength` to remove outdated
optimizations
(Rongjian Zhang) (https://github.com/nodejs/node/pull/38545)
- (SEMVER-MAJOR) buffer: expose Blob as a global
(James M Snell) (https://github.com/nodejs/node/pull/41270)
- (SEMVER-MAJOR) buffer: graduate Blob from experimental
(James M Snell) (https://github.com/nodejs/node/pull/41270)
- (SEMVER-MAJOR) build: make x86 Windows support temporarily
experimental
(Michaël Zasso) (https://github.com/nodejs/node/pull/42666)
- (SEMVER-MAJOR) build: bump macOS deployment target to 10.15
(Richard Lau) (https://github.com/nodejs/node/pull/42292)
- (SEMVER-MAJOR) build: downgrade Windows 8.1 and server 2012 R2 to
experimental
(Michaël Zasso) (https://github.com/nodejs/node/pull/42105)
- (SEMVER-MAJOR) child\_process: improve argument validation
(Rich Trott) (https://github.com/nodejs/node/pull/41305)
- (SEMVER-MAJOR) cluster: make `kill` to be just `process.kill`
(Bar Admoni) (https://github.com/nodejs/node/pull/34312)
- (SEMVER-MAJOR) crypto: cleanup validation
(Mohammed Keyvanzadeh) (https://github.com/nodejs/node/pull/39841)
- (SEMVER-MAJOR) crypto: prettify othername in PrintGeneralName
(Tobias Nießen) (https://github.com/nodejs/node/pull/42123)
- (SEMVER-MAJOR) crypto: fix X509Certificate toLegacyObject
(Tobias Nießen) (https://github.com/nodejs/node/pull/42124)
- (SEMVER-MAJOR) crypto: use RFC2253 format in PrintGeneralName
(Tobias Nießen) (https://github.com/nodejs/node/pull/42002)
- (SEMVER-MAJOR) crypto: change default check(Host|Email) behavior
(Tobias Nießen) (https://github.com/nodejs/node/pull/41600)
- (SEMVER-MAJOR) deps: V8: cherry-pick semver-major commits from 10.2
(Michaël Zasso) (https://github.com/nodejs/node/pull/42657)
- (SEMVER-MAJOR) deps: update V8 to 10.1.124.6
(Michaël Zasso) (https://github.com/nodejs/node/pull/42657)
- (SEMVER-MAJOR) deps: update V8 to 9.8.177.9
(Michaël Zasso) (https://github.com/nodejs/node/pull/41610)
- (SEMVER-MAJOR) deps: update V8 to 9.7.106.18
(Michaël Zasso) (https://github.com/nodejs/node/pull/40907)
- (SEMVER-MAJOR) dns: remove `dns.lookup` and `dnsPromises.lookup`
options type coercion
(Antoine du Hamel) (https://github.com/nodejs/node/pull/41431)
- (SEMVER-MAJOR) doc: update minimum glibc requirements for Linux
(Richard Lau) (https://github.com/nodejs/node/pull/42659)
- (SEMVER-MAJOR) doc: update AIX minimum supported arch
(Richard Lau) (https://github.com/nodejs/node/pull/42604)
- (SEMVER-MAJOR) fs: runtime deprecate string coercion in `fs.write`,
`fs.writeFileSync`
(Livia Medeiros) (https://github.com/nodejs/node/pull/42607)
- (SEMVER-MAJOR) http: refactor headersTimeout and requestTimeout logic
(Paolo Insogna) (https://github.com/nodejs/node/pull/41263)
- (SEMVER-MAJOR) http: make TCP noDelay enabled by default
(Paolo Insogna) (https://github.com/nodejs/node/pull/42163)
- (SEMVER-MAJOR) lib: enable fetch by default
(Michaël Zasso) (https://github.com/nodejs/node/pull/41811)
- (SEMVER-MAJOR) lib: replace validator and error
(Mohammed Keyvanzadeh) (https://github.com/nodejs/node/pull/41678)
- (SEMVER-MAJOR) module,repl: support 'node:'-only core modules
(Colin Ihrig) (https://github.com/nodejs/node/pull/42325)
- (SEMVER-MAJOR) net: make `server.address()` return an integer for
`family`
(Antoine du Hamel) (https://github.com/nodejs/node/pull/41431)
- (SEMVER-MAJOR) process: disallow some uses of Object.defineProperty()
on process.env
(Himself65) (https://github.com/nodejs/node/pull/28006)
- (SEMVER-MAJOR) process: runtime deprecate multipleResolves
(Benjamin Gruenbaum) (https://github.com/nodejs/node/pull/41896)
- (SEMVER-MAJOR) readline: fix question still called after closed
(Xuguang Mei) (https://github.com/nodejs/node/pull/42464)
- (SEMVER-MAJOR) stream: remove thenable support
(Robert Nagy) (https://github.com/nodejs/node/pull/40773)
- (SEMVER-MAJOR) stream: expose web streams globals, remove runtime
experimental warning
(Antoine du Hamel) (https://github.com/nodejs/node/pull/42225)
- (SEMVER-MAJOR) stream: need to cleanup event listeners if last stream
is readable
(Xuguang Mei) (https://github.com/nodejs/node/pull/41954)
- (SEMVER-MAJOR) stream: revert revert `map` spec compliance
(Benjamin Gruenbaum) (https://github.com/nodejs/node/pull/41933)
- (SEMVER-MAJOR) stream: throw invalid arg type from End Of Stream
(Jithil P Ponnan) (https://github.com/nodejs/node/pull/41766)
- (SEMVER-MAJOR) stream: don't emit finish after destroy
(Robert Nagy) (https://github.com/nodejs/node/pull/40852)
- (SEMVER-MAJOR) stream: add errored and closed props
(Robert Nagy) (https://github.com/nodejs/node/pull/40696)
- (SEMVER-MAJOR) test: add initial test module
(Colin Ihrig) (https://github.com/nodejs/node/pull/42325)
- (SEMVER-MAJOR) timers: refactor internal classes to ES2015 syntax
(Rabbit) (https://github.com/nodejs/node/pull/37408)
- (SEMVER-MAJOR) tls: represent registeredID numerically always
(Tobias Nießen) (https://github.com/nodejs/node/pull/41561)
- (SEMVER-MAJOR) tls: move tls.parseCertString to end-of-life
(Tobias Nießen) (https://github.com/nodejs/node/pull/41479)
- (SEMVER-MAJOR) url: throw on NULL in IPv6 hostname
(Rich Trott) (https://github.com/nodejs/node/pull/42313)
- (SEMVER-MAJOR) v8: make v8.writeHeapSnapshot() error codes consistent
(Darshan Sen) (https://github.com/nodejs/node/pull/42577)
- (SEMVER-MAJOR) v8: make writeHeapSnapshot throw if fopen fails
(Antonio Román) (https://github.com/nodejs/node/pull/41373)
- (SEMVER-MAJOR) worker: expose BroadcastChannel as a global
(James M Snell) (https://github.com/nodejs/node/pull/41271)
- (SEMVER-MAJOR) worker: graduate BroadcastChannel to supported
(James M Snell) (https://github.com/nodejs/node/pull/41271)
PR-URL: https://github.com/nodejs/node/pull/42262
2022-03-08 01:39:47 +00:00
|
|
|
- version: v18.0.0
|
2022-01-24 19:39:16 +03:30
|
|
|
pr-url: https://github.com/nodejs/node/pull/41678
|
|
|
|
description: Passing an invalid callback to the `callback` argument
|
|
|
|
now throws `ERR_INVALID_ARG_TYPE` instead of
|
|
|
|
`ERR_INVALID_CALLBACK`.
|
2016-12-12 17:08:31 -08:00
|
|
|
-->
|
|
|
|
|
2018-04-07 15:23:10 +03:00
|
|
|
* `method` {string}
|
|
|
|
* `params` {Object}
|
|
|
|
* `callback` {Function}
|
2016-12-12 17:08:31 -08:00
|
|
|
|
|
|
|
Posts a message to the inspector back-end. `callback` will be notified when
|
|
|
|
a response is received. `callback` is a function that accepts two optional
|
2019-10-23 21:28:42 -07:00
|
|
|
arguments: error and message-specific result.
|
2016-12-12 17:08:31 -08:00
|
|
|
|
|
|
|
```js
|
2017-05-24 04:05:06 +03:00
|
|
|
session.post('Runtime.evaluate', { expression: '2 + 2' },
|
|
|
|
(error, { result }) => console.log(result));
|
2016-12-12 17:08:31 -08:00
|
|
|
// Output: { type: 'number', value: 4, description: '4' }
|
|
|
|
```
|
|
|
|
|
|
|
|
The latest version of the V8 inspector protocol is published on the
|
|
|
|
[Chrome DevTools Protocol Viewer][].
|
|
|
|
|
2018-10-29 22:04:25 -07:00
|
|
|
Node.js inspector supports all the Chrome DevTools Protocol domains declared
|
2016-12-12 17:08:31 -08:00
|
|
|
by V8. Chrome DevTools Protocol domain provides an interface for interacting
|
|
|
|
with one of the runtime agents used to inspect the application state and listen
|
|
|
|
to the run-time events.
|
|
|
|
|
2023-01-29 11:32:23 +08:00
|
|
|
You can not set `reportProgress` to `true` when sending a
|
|
|
|
`HeapProfiler.takeHeapSnapshot` or `HeapProfiler.stopTrackingHeapObjects`
|
|
|
|
command to V8.
|
|
|
|
|
2022-10-13 20:12:05 -03:00
|
|
|
#### Example usage
|
2018-03-06 09:08:47 -08:00
|
|
|
|
2019-03-07 08:48:54 -08:00
|
|
|
Apart from the debugger, various V8 Profilers are available through the DevTools
|
|
|
|
protocol.
|
|
|
|
|
2022-10-13 20:12:05 -03:00
|
|
|
##### CPU profiler
|
2018-03-06 09:08:47 -08:00
|
|
|
|
2019-03-07 08:48:54 -08:00
|
|
|
Here's an example showing how to use the [CPU Profiler][]:
|
2018-03-06 09:08:47 -08:00
|
|
|
|
|
|
|
```js
|
2022-04-20 10:23:41 +02:00
|
|
|
const inspector = require('node:inspector');
|
|
|
|
const fs = require('node:fs');
|
2018-03-06 09:08:47 -08:00
|
|
|
const session = new inspector.Session();
|
|
|
|
session.connect();
|
|
|
|
|
|
|
|
session.post('Profiler.enable', () => {
|
|
|
|
session.post('Profiler.start', () => {
|
2019-01-21 01:22:27 +01:00
|
|
|
// Invoke business logic under measurement here...
|
2018-03-06 09:08:47 -08:00
|
|
|
|
|
|
|
// some time later...
|
2018-03-15 15:44:04 -07:00
|
|
|
session.post('Profiler.stop', (err, { profile }) => {
|
2019-03-07 01:03:53 +01:00
|
|
|
// Write profile to disk, upload, etc.
|
2018-03-15 15:44:04 -07:00
|
|
|
if (!err) {
|
|
|
|
fs.writeFileSync('./profile.cpuprofile', JSON.stringify(profile));
|
|
|
|
}
|
2018-03-06 09:08:47 -08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2022-10-13 20:12:05 -03:00
|
|
|
##### Heap profiler
|
2019-03-07 08:48:54 -08:00
|
|
|
|
|
|
|
Here's an example showing how to use the [Heap Profiler][]:
|
|
|
|
|
|
|
|
```js
|
2022-04-20 10:23:41 +02:00
|
|
|
const inspector = require('node:inspector');
|
|
|
|
const fs = require('node:fs');
|
2019-03-07 08:48:54 -08:00
|
|
|
const session = new inspector.Session();
|
|
|
|
|
|
|
|
const fd = fs.openSync('profile.heapsnapshot', 'w');
|
|
|
|
|
|
|
|
session.connect();
|
|
|
|
|
|
|
|
session.on('HeapProfiler.addHeapSnapshotChunk', (m) => {
|
|
|
|
fs.writeSync(fd, m.params.chunk);
|
|
|
|
});
|
|
|
|
|
|
|
|
session.post('HeapProfiler.takeHeapSnapshot', null, (err, r) => {
|
2019-09-26 09:02:45 +03:00
|
|
|
console.log('HeapProfiler.takeHeapSnapshot done:', err, r);
|
2019-03-07 08:48:54 -08:00
|
|
|
session.disconnect();
|
|
|
|
fs.closeSync(fd);
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2022-10-13 20:12:05 -03:00
|
|
|
## Common Objects
|
|
|
|
|
|
|
|
### `inspector.close()`
|
|
|
|
|
|
|
|
<!-- YAML
|
|
|
|
added: v9.0.0
|
|
|
|
changes:
|
|
|
|
- version: v18.10.0
|
|
|
|
pr-url: https://github.com/nodejs/node/pull/44489
|
|
|
|
description: The API is exposed in the worker threads.
|
|
|
|
-->
|
|
|
|
|
2023-06-20 20:22:53 -07:00
|
|
|
Attempts to close all remaining connections, blocking the event loop until all
|
|
|
|
are closed. Once all connections are closed, deactivates the inspector.
|
2022-10-13 20:12:05 -03:00
|
|
|
|
|
|
|
### `inspector.console`
|
|
|
|
|
|
|
|
* {Object} An object to send messages to the remote inspector console.
|
|
|
|
|
|
|
|
```js
|
|
|
|
require('node:inspector').console.log('a message');
|
|
|
|
```
|
|
|
|
|
|
|
|
The inspector console does not have API parity with Node.js
|
|
|
|
console.
|
|
|
|
|
|
|
|
### `inspector.open([port[, host[, wait]]])`
|
|
|
|
|
2023-07-16 12:46:27 +03:00
|
|
|
<!-- YAML
|
|
|
|
changes:
|
2023-08-15 18:09:46 +00:00
|
|
|
- version: v20.6.0
|
2023-07-16 12:46:27 +03:00
|
|
|
pr-url: https://github.com/nodejs/node/pull/48765
|
|
|
|
description: inspector.open() now returns a `Disposable` object.
|
|
|
|
-->
|
|
|
|
|
2022-10-13 20:12:05 -03:00
|
|
|
* `port` {number} Port to listen on for inspector connections. Optional.
|
|
|
|
**Default:** what was specified on the CLI.
|
|
|
|
* `host` {string} Host to listen on for inspector connections. Optional.
|
|
|
|
**Default:** what was specified on the CLI.
|
|
|
|
* `wait` {boolean} Block until a client has connected. Optional.
|
|
|
|
**Default:** `false`.
|
2024-02-14 00:37:42 +03:00
|
|
|
* Returns: {Disposable} A Disposable that calls [`inspector.close()`][].
|
2022-10-13 20:12:05 -03:00
|
|
|
|
|
|
|
Activate inspector on host and port. Equivalent to
|
|
|
|
`node --inspect=[[host:]port]`, but can be done programmatically after node has
|
|
|
|
started.
|
|
|
|
|
|
|
|
If wait is `true`, will block until a client has connected to the inspect port
|
|
|
|
and flow control has been passed to the debugger client.
|
|
|
|
|
|
|
|
See the [security warning][] regarding the `host`
|
|
|
|
parameter usage.
|
|
|
|
|
|
|
|
### `inspector.url()`
|
|
|
|
|
|
|
|
* Returns: {string|undefined}
|
|
|
|
|
|
|
|
Return the URL of the active inspector, or `undefined` if there is none.
|
|
|
|
|
|
|
|
```console
|
|
|
|
$ node --inspect -p 'inspector.url()'
|
|
|
|
Debugger listening on ws://127.0.0.1:9229/166e272e-7a30-4d09-97ce-f1c012b43c34
|
|
|
|
For help, see: https://nodejs.org/en/docs/inspector
|
|
|
|
ws://127.0.0.1:9229/166e272e-7a30-4d09-97ce-f1c012b43c34
|
|
|
|
|
|
|
|
$ node --inspect=localhost:3000 -p 'inspector.url()'
|
|
|
|
Debugger listening on ws://localhost:3000/51cf8d0e-3c36-4c59-8efd-54519839e56a
|
|
|
|
For help, see: https://nodejs.org/en/docs/inspector
|
|
|
|
ws://localhost:3000/51cf8d0e-3c36-4c59-8efd-54519839e56a
|
|
|
|
|
|
|
|
$ node -p 'inspector.url()'
|
|
|
|
undefined
|
|
|
|
```
|
|
|
|
|
|
|
|
### `inspector.waitForDebugger()`
|
|
|
|
|
|
|
|
<!-- YAML
|
|
|
|
added: v12.7.0
|
|
|
|
-->
|
|
|
|
|
|
|
|
Blocks until a client (existing or connected later) has sent
|
|
|
|
`Runtime.runIfWaitingForDebugger` command.
|
|
|
|
|
|
|
|
An exception will be thrown if there is no active inspector.
|
|
|
|
|
2024-07-19 14:00:30 +09:00
|
|
|
## Integration with DevTools
|
|
|
|
|
2025-04-17 21:38:57 +02:00
|
|
|
> Stability: 1.1 - Active development
|
|
|
|
|
2024-07-19 14:00:30 +09:00
|
|
|
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.
|
|
|
|
|
|
|
|
```js
|
|
|
|
// 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.org/en',
|
|
|
|
method: 'GET',
|
2024-11-20 19:10:38 +09:00
|
|
|
},
|
2024-07-19 14:00:30 +09:00
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
### `inspector.Network.requestWillBeSent([params])`
|
|
|
|
|
|
|
|
<!-- YAML
|
|
|
|
added:
|
2024-07-30 10:11:29 -03:00
|
|
|
- v22.6.0
|
2024-09-30 10:57:59 +02:00
|
|
|
- v20.18.0
|
2024-07-19 14:00:30 +09:00
|
|
|
-->
|
|
|
|
|
|
|
|
* `params` {Object}
|
|
|
|
|
|
|
|
This feature is only available with the `--experimental-network-inspection` flag enabled.
|
|
|
|
|
|
|
|
Broadcasts the `Network.requestWillBeSent` event to connected frontends. This event indicates that
|
|
|
|
the application is about to send an HTTP request.
|
|
|
|
|
|
|
|
### `inspector.Network.responseReceived([params])`
|
|
|
|
|
|
|
|
<!-- YAML
|
|
|
|
added:
|
2024-07-30 10:11:29 -03:00
|
|
|
- v22.6.0
|
2024-09-30 10:57:59 +02:00
|
|
|
- v20.18.0
|
2024-07-19 14:00:30 +09:00
|
|
|
-->
|
|
|
|
|
|
|
|
* `params` {Object}
|
|
|
|
|
|
|
|
This feature is only available with the `--experimental-network-inspection` flag enabled.
|
|
|
|
|
|
|
|
Broadcasts the `Network.responseReceived` event to connected frontends. This event indicates that
|
|
|
|
HTTP response is available.
|
|
|
|
|
|
|
|
### `inspector.Network.loadingFinished([params])`
|
|
|
|
|
|
|
|
<!-- YAML
|
|
|
|
added:
|
2024-07-30 10:11:29 -03:00
|
|
|
- v22.6.0
|
2024-09-30 10:57:59 +02:00
|
|
|
- v20.18.0
|
2024-07-19 14:00:30 +09:00
|
|
|
-->
|
|
|
|
|
|
|
|
* `params` {Object}
|
|
|
|
|
|
|
|
This feature is only available with the `--experimental-network-inspection` flag enabled.
|
|
|
|
|
|
|
|
Broadcasts the `Network.loadingFinished` event to connected frontends. This event indicates that
|
|
|
|
HTTP request has finished loading.
|
|
|
|
|
2024-08-11 20:42:01 +09:00
|
|
|
### `inspector.Network.loadingFailed([params])`
|
|
|
|
|
|
|
|
<!-- YAML
|
|
|
|
added:
|
2024-08-19 11:58:36 -03:00
|
|
|
- v22.7.0
|
2024-09-30 10:57:59 +02:00
|
|
|
- v20.18.0
|
2024-08-11 20:42:01 +09:00
|
|
|
-->
|
|
|
|
|
|
|
|
* `params` {Object}
|
|
|
|
|
|
|
|
This feature is only available with the `--experimental-network-inspection` flag enabled.
|
|
|
|
|
|
|
|
Broadcasts the `Network.loadingFailed` event to connected frontends. This event indicates that
|
|
|
|
HTTP request has failed to load.
|
|
|
|
|
2024-01-18 14:30:33 +08:00
|
|
|
## Support of breakpoints
|
|
|
|
|
|
|
|
The Chrome DevTools Protocol [`Debugger` domain][] allows an
|
|
|
|
`inspector.Session` to attach to a program and set breakpoints to step through
|
|
|
|
the codes.
|
|
|
|
|
|
|
|
However, setting breakpoints with a same-thread `inspector.Session`, which is
|
|
|
|
connected by [`session.connect()`][], should be avoided as the program being
|
|
|
|
attached and paused is exactly the debugger itself. Instead, try connect to the
|
|
|
|
main thread by [`session.connectToMainThread()`][] and set breakpoints in a
|
|
|
|
worker thread, or connect with a [Debugger][] program over WebSocket
|
|
|
|
connection.
|
|
|
|
|
2018-03-06 09:08:47 -08:00
|
|
|
[CPU Profiler]: https://chromedevtools.github.io/devtools-protocol/v8/Profiler
|
2018-11-27 11:49:21 -08:00
|
|
|
[Chrome DevTools Protocol Viewer]: https://chromedevtools.github.io/devtools-protocol/v8/
|
2024-01-18 14:30:33 +08:00
|
|
|
[Debugger]: debugger.md
|
2019-03-07 08:48:54 -08:00
|
|
|
[Heap Profiler]: https://chromedevtools.github.io/devtools-protocol/v8/HeapProfiler
|
2020-09-17 18:53:37 +02:00
|
|
|
[`'Debugger.paused'`]: https://chromedevtools.github.io/devtools-protocol/v8/Debugger#event-paused
|
2024-01-18 14:30:33 +08:00
|
|
|
[`Debugger` domain]: https://chromedevtools.github.io/devtools-protocol/v8/Debugger
|
2023-07-16 12:46:27 +03:00
|
|
|
[`inspector.close()`]: #inspectorclose
|
2021-07-04 20:39:17 -07:00
|
|
|
[`session.connect()`]: #sessionconnect
|
2024-01-18 14:30:33 +08:00
|
|
|
[`session.connectToMainThread()`]: #sessionconnecttomainthread
|
2021-07-04 20:39:17 -07:00
|
|
|
[security warning]: cli.md#warning-binding-inspector-to-a-public-ipport-combination-is-insecure
|
2024-01-18 14:30:33 +08:00
|
|
|
[support of breakpoints]: #support-of-breakpoints
|