Inspector
Thenode:inspector module provides an API for interacting with the V8 inspector.
Stability
Stable (Stability: 2)Import
Promises API
Class: inspector.Session
Used for dispatching messages to the V8 inspector backend.new inspector.Session()
Create a new inspector session. Must call session.connect() before dispatching messages.
When using Session, console output is not released unless you run Runtime.DiscardConsoleEntries.
Event: ‘inspectorNotification’
Emitted when any notification from V8 Inspector is received. Parameters:- - The notification message object
Event: <inspector-protocol-method>
Emitted when a specific inspector notification is received.
session.connect()
Connects the session to the inspector backend.
session.connectToMainThread()
Connects to the main thread inspector backend. Only works from Worker threads.
session.disconnect()
Immediately closes the session. Pending callbacks receive errors. Reconnecting requires calling connect() again.
session.post(method[, params])
Posts a message to the inspector backend.
Parameters:
method- Inspector protocol methodparams- Method parameters
Example: CPU Profiler
Example: Heap Profiler
Callback API
Class: inspector.Session
Same as Promises API but uses callbacks.session.post(method[, params][, callback])
Posts a message with optional callback.
Parameters:
method- Inspector protocol methodparams- Method parameterscallback- Called with (error, result)
Common Objects
inspector.close()
Attempts to close all connections and deactivate the inspector.
inspector.console
Object to send messages to the remote inspector console.
inspector.open([port[, host[, wait]]])
Activate inspector programmatically.
Parameters:
port- Port to listen on (default: CLI value)host- Host to listen on (default: CLI value)wait- Block until client connects (default:false)
inspector.close() on disposal
Equivalent to node --inspect=[[host:]port].
inspector.url()
Returns: - URL of the active inspector or undefined
inspector.waitForDebugger()
Blocks until a client sends the Runtime.runIfWaitingForDebugger command.
Throws if there is no active inspector.
Integration with DevTools
The inspector module provides APIs to integrate with devtools supporting Chrome DevTools Protocol.Network Inspection
Requires--experimental-network-inspection flag.
inspector.Network.requestWillBeSent([params])
Broadcasts that the application is about to send an HTTP request.
Parameters:
params- Request details
inspector.Network.responseReceived([params])
Broadcasts that HTTP response is available.
Parameters:
params- Response details
inspector.Network.loadingFinished([params])
Broadcasts that HTTP request has finished loading.
Parameters:
params- Loading details
inspector.Network.loadingFailed([params])
Broadcasts that HTTP request has failed.
Parameters:
params- Error details
inspector.Network.dataReceived([params])
Broadcasts data received event or buffers data.
Parameters:
params- Data details
Network.getResponseBody command.
inspector.Network.dataSent([params])
Enables Network.getRequestPostData command.
Parameters:
params- Data details
inspector.Network.webSocketCreated([params])
Broadcasts WebSocket connection initiation.
Parameters:
params- WebSocket details
inspector.Network.webSocketHandshakeResponseReceived([params])
Broadcasts WebSocket handshake response received.
Parameters:
params- Handshake details
inspector.Network.webSocketClosed([params])
Broadcasts WebSocket connection closed.
Parameters:
params- Close details
Resource Management
Requires--experimental-inspector-network-resource flag.
inspector.NetworkResources.put(url, content)
Provide resource content for CDP loadNetworkResource requests.
Parameters:
url- Resource URLcontent- Resource content
Storage Inspection
Requires--experimental-storage-inspection flag.
inspector.DOMStorage.domStorageItemAdded(params)
Broadcasts that a new item was added to storage.
Parameters:
paramsstorageIdsecurityOriginstorageKeyisLocalStorage
keynewValue
inspector.DOMStorage.domStorageItemRemoved(params)
Broadcasts that an item was removed from storage.
inspector.DOMStorage.domStorageItemUpdated(params)
Broadcasts that a storage item was updated.
inspector.DOMStorage.domStorageItemsCleared(params)
Broadcasts that all items were cleared from storage.
inspector.DOMStorage.registerStorage(params)
Register storage for inspection.
Parameters:
paramsisLocalStoragestorageMap
Support of Breakpoints
Avoid setting breakpoints with same-threadinspector.Session. Use session.connectToMainThread() from Worker threads or connect via WebSocket instead.