[whatwg] Stack trace in window.onerror

Ian Hickson ian at hixie.ch
Wed Jul 24 11:50:09 PDT 2013

On Fri, 12 Jul 2013, James Greene wrote:
> On Fri, Jul 12, 2013 at 12:17 PM, Ian Hickson <ian at hixie.ch> wrote:
> > On Tue, 5 Feb 2013, Nathan Broadbent wrote:
> > >
> > > The current information passed to window.onerror rarely provides 
> > > sufficient information to find the cause of the error. The column 
> > > number argument will be a big step forward, but a stack trace would 
> > > be especially useful. I would like to add my support for improving 
> > > the window.onerror arguments, with a fifth argument for stack trace. 
> > > Is there anything that James or I could do to move this discussion 
> > > along?
> >
> > This seems useful, but I don't think it's specific to window.onerror. 
> > I would recommend approaching the es-discuss list about this.
> I'm curious: would do you say that?  All evergreen browsers already 
> include a `stack` property on their core `Error` prototypes, so it seems 
> to me that the only thing preventing us from getting that useful 
> information for unhandled errors is the fact that `window.onerror` does 
> not provide us with a real Error object instances (or even fake ones 
> with shell properties in the case of cross-domain errors).

Ah, I was unaware of Error.stack. Interesting!

I've added a fifth argument to onerror, which has the exception object.

On Fri, 12 Jul 2013, James Greene wrote:
> I'd rather get an Error-like duck-typed object with this shell info for 
> cross-domain requests than to not get a real Error object when the 
> unhandled error *is* from the same origin.

For the cross-origin case, I've set error to null.

> Adding the trace as another new argument to `window.onerror` is 
> certainly an option but the parameter list is getting long and I suspect 
> that Error prototypes may still gain additional properties in the 
> future.

Yeah, exposing the error itself seemed better.

On Fri, 12 Jul 2013, Elliott Sprehn wrote:
> Can we just add a new event that takes an event object instead of a huge 
> list of arguments? :)

There's already an event. You can get it if you use addEventListener() for 
'error' rather than using onerror.

(It's also exposed on the event object, for those of you using 
addEventListener() for error events rather than onerror.)

Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'

More information about the whatwg mailing list