Programmatically capture Chrome Async Javascript stack trace : <p>I've been working on trying to add some better error logging to a web application that is only run on Chrome. In essence, I want to be able to capture and store stack traces. For synchronous code, this works fine, but for async code, I've run into something a tad strange. Essentially, Chrome appears to log additional information as part of its async stack trace feature, but I haven't been able to figure out how to capture it.</p>

<p>Code, to run in Chrome browser console:</p>

<pre><code>let e;
let a = () =&gt; Promise.resolve(null)
.then(() =&gt; (null).foo)
.catch(err =&gt; {
  console.info(err); 
  console.error(err); 
  e = err;
})
let b = () =&gt; a();
let c = () =&gt; b();
c();
</code></pre>

<p>Output:</p>

<pre><code>(info)
TypeError: Cannot read property 'foo' of null
    at &lt;anonymous&gt;:3:20

(error, after expanding)
TypeError: Cannot read property 'foo' of null
    at &lt;anonymous&gt;:3:20
(anonymous) @ VM1963:6
Promise.catch (async)
a @ VM1963:4
b @ VM1963:9
c @ VM1963:10
(anonymous) @ VM1963:11
</code></pre>

<p>So <code>console.error</code> gives me a stack trace threaded all the way through the callstack, presumably through some form of Chrome engine magick. <code>console.info</code> gives me the actual stack trace that's stored on <code>err</code>. If after this is all done I attempt to read the value of <code>e</code>, its stack is the two lines I get from the <code>console.info</code> statement, not the <code>console.error</code> statement.</p>

<p>What I'm asking is, is there any way to capture and store the async stack trace that Chrome is generating and using when I call <code>console.error</code>?</p>
