`;",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"params": [
{
"textRaw": "{Object} The notification message object",
"type": "Object",
"desc": "The notification message object"
}
],
"desc": "Emitted when an inspector notification is received that has its method field set\nto the <inspector-protocol-method>
value.
\nThe following snippet installs a listener on the 'Debugger.paused'
\nevent, and prints the reason for program suspension whenever program\nexecution is suspended (through breakpoints, for example):
\nsession.on('Debugger.paused', ({ params }) => {\n console.log(params.hitBreakpoints);\n});\n// [ '/the/file/that/has/the/breakpoint.js:11:0' ]\n
"
}
],
"methods": [
{
"textRaw": "`session.connect()`",
"type": "method",
"name": "connect",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"signatures": [
{
"params": []
}
],
"desc": "Connects a session to the inspector back-end.
"
},
{
"textRaw": "`session.connectToMainThread()`",
"type": "method",
"name": "connectToMainThread",
"meta": {
"added": [
"v12.11.0"
],
"changes": []
},
"signatures": [
{
"params": []
}
],
"desc": "Connects a session to the main thread inspector back-end. An exception will\nbe thrown if this API was not called on a Worker thread.
"
},
{
"textRaw": "`session.disconnect()`",
"type": "method",
"name": "disconnect",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"signatures": [
{
"params": []
}
],
"desc": "Immediately close the session. All pending message callbacks will be called\nwith an error. session.connect()
will need to be called to be able to send\nmessages again. Reconnected session will lose all inspector state, such as\nenabled agents or configured breakpoints.
"
},
{
"textRaw": "`session.post(method[, params][, callback])`",
"type": "method",
"name": "post",
"meta": {
"added": [
"v8.0.0"
],
"changes": []
},
"signatures": [
{
"params": [
{
"textRaw": "`method` {string}",
"name": "method",
"type": "string"
},
{
"textRaw": "`params` {Object}",
"name": "params",
"type": "Object"
},
{
"textRaw": "`callback` {Function}",
"name": "callback",
"type": "Function"
}
]
}
],
"desc": "Posts a message to the inspector back-end. callback
will be notified when\na response is received. callback
is a function that accepts two optional\narguments: error and message-specific result.
\nsession.post('Runtime.evaluate', { expression: '2 + 2' },\n (error, { result }) => console.log(result));\n// Output: { type: 'number', value: 4, description: '4' }\n
\nThe latest version of the V8 inspector protocol is published on the\nChrome DevTools Protocol Viewer.
\nNode.js inspector supports all the Chrome DevTools Protocol domains declared\nby V8. Chrome DevTools Protocol domain provides an interface for interacting\nwith one of the runtime agents used to inspect the application state and listen\nto the run-time events.
\nExample usage
\nApart from the debugger, various V8 Profilers are available through the DevTools\nprotocol.
"
}
],
"modules": [
{
"textRaw": "CPU profiler",
"name": "cpu_profiler",
"desc": "Here's an example showing how to use the CPU Profiler:
\nconst inspector = require('node:inspector');\nconst fs = require('node:fs');\nconst session = new inspector.Session();\nsession.connect();\n\nsession.post('Profiler.enable', () => {\n session.post('Profiler.start', () => {\n // Invoke business logic under measurement here...\n\n // some time later...\n session.post('Profiler.stop', (err, { profile }) => {\n // Write profile to disk, upload, etc.\n if (!err) {\n fs.writeFileSync('./profile.cpuprofile', JSON.stringify(profile));\n }\n });\n });\n});\n
",
"type": "module",
"displayName": "CPU profiler"
},
{
"textRaw": "Heap profiler",
"name": "heap_profiler",
"desc": "Here's an example showing how to use the Heap Profiler:
\nconst inspector = require('node:inspector');\nconst fs = require('node:fs');\nconst session = new inspector.Session();\n\nconst fd = fs.openSync('profile.heapsnapshot', 'w');\n\nsession.connect();\n\nsession.on('HeapProfiler.addHeapSnapshotChunk', (m) => {\n fs.writeSync(fd, m.params.chunk);\n});\n\nsession.post('HeapProfiler.takeHeapSnapshot', null, (err, r) => {\n console.log('HeapProfiler.takeHeapSnapshot done:', err, r);\n session.disconnect();\n fs.closeSync(fd);\n});\n
",
"type": "module",
"displayName": "Heap profiler"
}
],
"signatures": [
{
"params": [],
"desc": "Create a new instance of the inspector.Session
class. The inspector session\nneeds to be connected through session.connect()
before the messages\ncan be dispatched to the inspector backend.
"
}
]
}
],
"type": "module",
"displayName": "Inspector"
}
]
}