google-chrome-devtoolschrome-devtools-protocol

how to get chrome devtools request initiator call stack?


Can I get the stack through code?

stack demo

I try to use chrome-remote-interface to get stack, but i find params.initiator.stack?.parent is always null.

const CDP = require("chrome-remote-interface");

(async function () {
  let client;
  try {
    client = await CDP();

    const { Page, Network } = client;

    await Promise.all([Page.enable(), Network.enable()]);

    Network.requestWillBeSent((params) => {
      console.log("Request URL:", params.request.url);
      console.log("Request Stack Trace:", params.initiator.stack?.parent);
    });

    await Page.navigate({
      url: "xxxxx",
    });
  } catch (err) {
    console.error(err);
  }
})();


Solution

  • By default collecting async stack trace is disabled. First you need to enable Debugger domain, then set setAsyncCallStackDepth to a non-zero value.