Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A lightweight and simple-to-use javascript exception notifier for Hoptoad / Airbrake

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.textile
Octocat-spinner-32 notifier.js
Octocat-spinner-32 notifier.min.js
README.textile

Exception Notifier For Hoptoad / Airbrake

A lightweight and simple-to-use notifier for Hoptoad / Airbrake

  • Includes basic error information (error message, line number, file, user agent, referrer)
  • Optimized file size for optimal performance (1021 bytes or 633 bytes gzipped)
  • Library agnostic
  • Works in all browsers that support the onerror event (IE 6+, Firefox, Safari, Chrome)

How To Use

Include the following above all your other javascript:

<script>var AIRBRAKE_API_KEY = 'xxxxxxxxxx';</script>
<script src="path/to/notifier.min.js"></script>

You probably also want to make sure that errors are only send to Airbrake when your site runs in production mode:

<%- if Rails.env.production? %>
<script>var AIRBRAKE_API_KEY = 'xxxxxxxxxx';</script>
<script src="path/to/notifier.min.js"></script>
<%- end %>

Or pass the current environment like:

<script>
  var AIRBRAKE_API_KEY = 'xxxxxxxxxxx';
  var AIRBRAKE_ENVIRONMENT = 'staging';
</script>
<script src="path/to/notifier.min.js"></script>

Now every uncatched exception in your javascript code will be sent to your Airbrake account.

You can also catch errors and send them to Airbrake by yourself:

try {
  doSomething();
} catch(e) {
  window.Airbrake && Airbrake.notify(e.message, e.fileName, e.lineNumber);
}

Why Should I Use This Rather Than The Built-In Hoptoad JavaScript Notifier?

Well, you don’t have to.
I decided to write my own javascript notifier since the standard hoptoad notifier feels very clumsy (7.75KB or 3.08KB gzipped) and is packed with features I don’t need.
However, if you need extended error information (including a proper stack trace etc.) you should rather use the hoptoad code.

Something went wrong with that request. Please try again.