{ "source": "doc/api/inspector.md", "modules": [ { "textRaw": "Inspector", "name": "inspector", "stability": 1, "stabilityText": "Experimental", "desc": "

The inspector module provides an API for interacting with the V8 inspector.

\n

It can be accessed using:

\n
const inspector = require('inspector');\n
\n", "methods": [ { "textRaw": "inspector.open([port[, host[, wait]]])", "type": "method", "name": "open", "signatures": [ { "params": [ { "textRaw": "port {number} Port to listen on for inspector connections. Optional, defaults to what was specified on the CLI. ", "name": "port", "type": "number", "desc": "Port to listen on for inspector connections. Optional, defaults to what was specified on the CLI.", "optional": true }, { "textRaw": "host {string} Host to listen on for inspector connections. Optional, defaults to what was specified on the CLI. ", "name": "host", "type": "string", "desc": "Host to listen on for inspector connections. Optional, defaults to what was specified on the CLI.", "optional": true }, { "textRaw": "wait {boolean} Block until a client has connected. Optional, defaults to false. ", "name": "wait", "type": "boolean", "desc": "Block until a client has connected. Optional, defaults to false.", "optional": true } ] }, { "params": [ { "name": "port", "optional": true }, { "name": "host", "optional": true }, { "name": "wait", "optional": true } ] } ], "desc": "

Activate inspector on host and port. Equivalent to node\n--inspect=[[host:]port], but can be done programatically after node has\nstarted.

\n

If wait is true, will block until a client has connected to the inspect port\nand flow control has been passed to the debugger client.

\n", "methods": [ { "textRaw": "inspector.close()", "type": "method", "name": "close", "desc": "

Deactivate the inspector. Blocks until there are no active connections.

\n", "signatures": [ { "params": [] } ] }, { "textRaw": "inspector.url()", "type": "method", "name": "url", "desc": "

Return the URL of the active inspector, or undefined if there is none.

\n", "signatures": [ { "params": [] } ] } ] } ], "classes": [ { "textRaw": "Class: inspector.Session", "type": "class", "name": "inspector.Session", "desc": "

The inspector.Session is used for dispatching messages to the V8 inspector\nback-end and receiving message responses and notifications.

\n", "methods": [ { "textRaw": "Constructor: new inspector.Session()", "type": "method", "name": "Session", "meta": { "added": [ "v8.0.0" ], "changes": [] }, "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.

\n

inspector.Session is an EventEmitter with the following events:

\n", "signatures": [ { "params": [] } ] }, { "textRaw": "session.connect()", "type": "method", "name": "connect", "meta": { "added": [ "v8.0.0" ], "changes": [] }, "desc": "

Connects a session to the inspector back-end. An exception will be thrown\nif there is already a connected session established either through the API or by\na front-end connected to the Inspector WebSocket port.

\n", "signatures": [ { "params": [] } ] }, { "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", "optional": true }, { "textRaw": "callback {Function} ", "name": "callback", "type": "Function", "optional": true } ] }, { "params": [ { "name": "method" }, { "name": "params", "optional": true }, { "name": "callback", "optional": true } ] } ], "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.

\n
session.post('Runtime.evaluate', { expression: '2 + 2' },\n             (error, { result }) => console.log(result));\n// Output: { type: 'number', value: 4, description: '4' }\n
\n

The latest version of the V8 inspector protocol is published on the\nChrome DevTools Protocol Viewer.

\n

Node 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.

\n" }, { "textRaw": "session.disconnect()", "type": "method", "name": "disconnect", "meta": { "added": [ "v8.0.0" ], "changes": [] }, "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.

\n", "signatures": [ { "params": [] } ] } ], "events": [ { "textRaw": "Event: 'inspectorNotification'", "type": "event", "name": "inspectorNotification", "meta": { "added": [ "v8.0.0" ], "changes": [] }, "params": [], "desc": "

Emitted when any notification from the V8 Inspector is received.

\n
session.on('inspectorNotification', (message) => console.log(message.method));\n// Debugger.paused\n// Debugger.resumed\n
\n

It is also possible to subscribe only to notifications with specific method:

\n" }, { "textRaw": "Event: <inspector-protocol-method>", "type": "event", "name": "<inspector-protocol-method>", "meta": { "added": [ "v8.0.0" ], "changes": [] }, "params": [], "desc": "

Emitted when an inspector notification is received that has its method field set\nto the <inspector-protocol-method> value.

\n

The 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):

\n
session.on('Debugger.paused', ({ params }) => {\n  console.log(params.hitBreakpoints);\n});\n// [ '/the/file/that/has/the/breakpoint.js:11:0' ]\n
\n" } ] } ], "type": "module", "displayName": "Inspector" } ] }