sleepless_in_seattle
sleepless_in_seattle

Reputation: 2214

Collecting javascript errors from users

Some of our customers are reporting that they are unable to execute some javascript actions. Our error data collecting is on the server and when javascript breaks we are unable to get notified it since ajax calls can't be run before page refresh.

Is there a way to collect javascript errors on client side and send them to the server as soon as javascript is running fine again.

Example:

  1. User goes to page a.php.
  2. There's faulty javascript on a.php and it breaks user's javascript.
  3. User's client logs the errors and stores it locally.
  4. User goes to page b.php.
  5. There are no faulty javascript on b.php and the client detects that there's javascript error logs stored locally and proceeds to send them to the server.
  6. The server writes the log up.

Upvotes: 1

Views: 294

Answers (2)

Guffa
Guffa

Reputation: 700342

There is no need to refresh the page to make AJAX calls. You just need to make sure that the error handling code is in its own script tag so that it won't break if there is a syntax error in the other code.

Here is part of the code that we are using to catch script errors and send them to the server (The AJAX code is in a separate method, but I trust that you already know how to do that):

window.onerror = function (message, url, line, column) {
    Ajax.logError(message, url, line, column);
    $('body').append($('<div>').addClass('ErrorPanel').text('An error occured in the browser.').delay(5000).animate({ height: 0 }, 2000, function() { $(this).remove(); }));
    return false;
};

Upvotes: 2

Tom Drissen
Tom Drissen

Reputation: 323

Maybe you should take a look at New Relic. New Relic is a monitoring tool for software analysis and it's able to show you various information about JavaScript errors (and much more):

http://newrelic.com/browser-monitoring

Upvotes: -1

Related Questions