Can `window.onerror` be used to write the error stack trace as a global error handler

I am trying to make a global error handler for any javascript error in the browser, so I used this code in the tag <head>

:

window.onerror = function(msg, url, line, col, error) {
    // Note that col & error are new to the HTML 5 spec and may not be
    // supported in every browser.  It worked for me in Chrome.
    var extra = !col ? '' : '\ncolumn: ' + col;
    extra += !error ? '' : '\nerror: ' + error;

    // You can view the information in an alert to see things working like this:
    alert("Error: " + msg + "\nurl: " + url + "\nline: " + line + extra);

    // TODO: Report this error via ajax so you can keep track
    //       of what pages have JS issues

    var suppressErrorAlert = true;
    // If you return true, then error alerts (like in older versions of
    // Internet Explorer) will be suppressed.
    return suppressErrorAlert;
};

      

But since I'm using a CDN with minifying my javascript files, I always get these useless values โ€‹โ€‹passed to the function:

msg: Script error.

url: ''

string: 0

col: 0

error: null

(results from Chrome version 43.0.2357.125 (64-bit)

on Ubuntu)

So, is there anyway I can get the error stack trace (or even any information about it) from within window.onerror

?

+3
javascript debugging stack-trace error-handling tracking


source to share


No one has answered this question yet

See similar questions:

425
How can I get JavaScript stack trace when throwing an exception?

or similar:

1415
How do I convert the stack trace to a string?
925
Get current stack trace in Java
538
What is a stack trace, and how can I use it to debug my application's errors?
462
How to print a stack trace in Node.js?
425
How can I get JavaScript stack trace when throwing an exception?
344
Get the description of the exception and the stack trace that caused the exception, all as a string
311
Displaying the stack trace from a running Python application
280
How to print the current stack trace in .NET without any exceptions?
29
When will the correct stack traces be executed in the window.onError function?
3
Pb to catch random JS error, window.onerror does not show line number in UIWebView (phone delay) - undefined



All Articles
Loading...
X
Show
Funny
Dev
Pics