On this page

Integration with DevTools

History
Stability: 1.1Active development

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.

// 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',
  },
});
M

inspector.Network.dataReceived

History
inspector.Network.dataReceived(params?): void
Attributes
params:Object

This feature is only available with the --experimental-network-inspection flag enabled.

Broadcasts the Network.dataReceived event to connected frontends, or buffers the data if Network.streamResourceContent command was not invoked for the given request yet.

Also enables Network.getResponseBody command to retrieve the response data.

M

inspector.Network.dataSent

History
inspector.Network.dataSent(params?): void
Attributes
params:Object

This feature is only available with the --experimental-network-inspection flag enabled.

Enables Network.getRequestPostData command to retrieve the request data.

M

inspector.Network.requestWillBeSent

History
inspector.Network.requestWillBeSent(params?): void
Attributes
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.

M

inspector.Network.responseReceived

History
inspector.Network.responseReceived(params?): void
Attributes
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.

M

inspector.Network.loadingFinished

History
inspector.Network.loadingFinished(params?): void
Attributes
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.

M

inspector.Network.loadingFailed

History
inspector.Network.loadingFailed(params?): void
Attributes
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.

M

inspector.Network.webSocketCreated

History
inspector.Network.webSocketCreated(params?): void
Attributes
params:Object

This feature is only available with the --experimental-network-inspection flag enabled.

Broadcasts the Network.webSocketCreated event to connected frontends. This event indicates that a WebSocket connection has been initiated.

inspector.Network.webSocketHandshakeResponseReceived(params?): void
Attributes
params:Object

This feature is only available with the --experimental-network-inspection flag enabled.

Broadcasts the Network.webSocketHandshakeResponseReceived event to connected frontends. This event indicates that the WebSocket handshake response has been received.

M

inspector.Network.webSocketClosed

History
inspector.Network.webSocketClosed(params?): void
Attributes
params:Object

This feature is only available with the --experimental-network-inspection flag enabled.

Broadcasts the Network.webSocketClosed event to connected frontends. This event indicates that a WebSocket connection has been closed.

P

inspector.NetworkResources.put

History
Stability: 1.1Active Development

This feature is only available with the --experimental-inspector-network-resource flag enabled.

The inspector.NetworkResources.put method is used to provide a response for a loadNetworkResource request issued via the Chrome DevTools Protocol (CDP). This is typically triggered when a source map is specified by URL, and a DevTools frontend—such as Chrome—requests the resource to retrieve the source map.

This method allows developers to predefine the resource content to be served in response to such CDP requests.

const inspector = require('node:inspector');
// By preemptively calling put to register the resource, a source map can be resolved when
// a loadNetworkResource request is made from the frontend.
async function setNetworkResources() {
  const mapUrl = 'http://localhost:3000/dist/app.js.map';
  const tsUrl = 'http://localhost:3000/src/app.ts';
  const distAppJsMap = await fetch(mapUrl).then((res) => res.text());
  const srcAppTs = await fetch(tsUrl).then((res) => res.text());
  inspector.NetworkResources.put(mapUrl, distAppJsMap);
  inspector.NetworkResources.put(tsUrl, srcAppTs);
};
setNetworkResources().then(() => {
  require('./dist/app');
});

For more details, see the official CDP documentation: Network.loadNetworkResource

P

inspector.DOMStorage.domStorageItemAdded

History
Attributes
params:Object
storageId:Object
securityOrigin:string
storageKey:string
isLocalStorage:boolean
key:string
newValue:string

This feature is only available with the --experimental-storage-inspection flag enabled.

Broadcasts the DOMStorage.domStorageItemAdded event to connected frontends. This event indicates that a new item has been added to the storage.

P

inspector.DOMStorage.domStorageItemRemoved

History
Attributes
params:Object
storageId:Object
securityOrigin:string
storageKey:string
isLocalStorage:boolean
key:string

This feature is only available with the --experimental-storage-inspection flag enabled.

Broadcasts the DOMStorage.domStorageItemRemoved event to connected frontends. This event indicates that an item has been removed from the storage.

P

inspector.DOMStorage.domStorageItemUpdated

History
Attributes
params:Object
storageId:Object
securityOrigin:string
storageKey:string
isLocalStorage:boolean
key:string
oldValue:string
newValue:string

This feature is only available with the --experimental-storage-inspection flag enabled.

Broadcasts the DOMStorage.domStorageItemUpdated event to connected frontends. This event indicates that a storage item has been updated.

P

inspector.DOMStorage.domStorageItemsCleared

History
Attributes
params:Object
storageId:Object
securityOrigin:string
storageKey:string
isLocalStorage:boolean

This feature is only available with the --experimental-storage-inspection flag enabled.

Broadcasts the DOMStorage.domStorageItemsCleared event to connected frontends. This event indicates that all items have been cleared from the storage.

P

inspector.DOMStorage.registerStorage

History
Attributes
params:Object
isLocalStorage:boolean
storageMap:Object

This feature is only available with the --experimental-storage-inspection flag enabled.