Any way to detect an async stack trace (like Chrome devtools does)?

kai zhu kaizhu256 at
Wed Jul 8 09:13:45 UTC 2020

here's a simple throwaway-function you can wrap around promises like fetch
to get the caller's async-stack-trace `promiseWithErrorStack`:

<!doctype html>
<html lang="en">
(async function foo() {
    function promiseWithErrorStack(promise) {
     * this function will append current-stack to any err caught from
        let errStack;
        errStack = new Error().stack;
        return new Promise(function (resolve, reject) {
            promise.then(resolve).catch(function (err) {
                // append current errStack to err.stack
                if (err && typeof err.stack === "string") {
                    err.stack += "\n" + errStack;
    await promiseWithErrorStack(fetch("")); // at foo


    Uncaught (in promise) TypeError: Failed to fetch
        at promiseWithErrorStack (test.html:12)
        at foo (test.html:23) // async-stack-trace
        at test.html:32

On Tue, Jul 7, 2020 at 11:54 PM #!/JoePea <joe at> wrote:

> Is there some way (perhaps by patching methods on objects?) so we can
> track async call stacks?
> When we pause code in devtools, we are able to see the async stack
> trace of the code.
> What I'd like to do is to effectively detect the same thing as
> devtools does at some point in any code. As a specific example, I'd
> like to detect the async stack trace of any call to `fetch`.
> Is such a thing possible with runtime code?
> Or would it require instrumentation of the source code?
> #!/JoePea
> _______________________________________________
> es-discuss mailing list
> es-discuss at
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list