First you need to initialize the notifier (You can find your project ID and API KEY with your project's settings):
var airbrake = new airbrakeJs.Client({projectId: <Your project ID>, projectKey: '<Your project API KEY>'});
Or if you are using browserify/webpack/etc:
var airbrakeJs = require('airbrake-js');
var airbrake = new airbrakeJs({projectId: <Your project ID>, projectKey: '<Your project API KEY>'});
The simplest method is to report errors directly:
try {
// This will throw if the document has no head tag
document.head.insertBefore(document.createElement('style'));
} catch(err) {
airbrake.notify(err);
throw err;
}
Alternatively you can wrap any code which may throw errors using the client's wrap method:
var startApp = function() {
// This will throw if the document has no head tag.
document.head.insertBefore(document.createElement('style'));
}
startApp = airbrake.wrap(startApp);
// Any exceptions thrown in startApp will be reported to Airbrake.
startApp();
Installation
Using npm
Using bower
Setup
The notifier is built using a standalone browserify build and can be used with:
We include the full source code with the package, so you can use Browserify too.
If you prefer not to host the library yourself, airbrake-js is available on the excellent cdnjs CDN.
Basic Usage
First you need to initialize the notifier (You can find your project ID and API KEY with your project's settings):
Or if you are using browserify/webpack/etc:
The simplest method is to report errors directly:
Alternatively you can wrap any code which may throw errors using the client's
wrap
method:For more information please visit our official GitHub Repo.