inspector.NetworkResources.put
\Stability: 1.1 - Active Development
此功能仅在启用 --experimental-inspector-network-resource 标志时可用。
\This feature is only available with the --experimental-inspector-network-resource flag enabled.
inspector.NetworkResources.put 方法用于为通过 Chrome DevTools 协议 (CDP) 发送的 loadNetworkResource 请求提供响应。这通常在通过 URL 指定源映射,并且 DevTools 前端(例如 Chrome)请求资源以检索源映射时触发。
\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.
此方法允许开发者预定义响应此类 CDP 请求时要提供的资源内容。
\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');
}); 更多详情,请参阅官方 CDP 文档:Network.loadNetworkResource
\For more details, see the official CDP documentation: Network.loadNetworkResource