Browser Integration Guide

Installation

To use our hosted CDN, place the following code between the <head></head> tags of your page:

<script src="//js.honeybadger.io/v0.5/honeybadger.min.js" type="text/javascript" data-apiKey="project api key" data-environment="production" data-revision="git SHA/project version"></script>

If using a bundler or including the library in some other way, Honeybadger may also be configured via JavaScript using Honeybadger.configure:

<script type="text/javascript">
  Honeybadger.configure({
    apiKey: 'project api key',
    environment: 'production',
    revision: 'git SHA/project version'
  });
</script>

Here's a video walkthrough of a basic, global installation:

Using Honeybadger with Javascript

Installing via NPM/YARN

# npm
npm install honeybadger-js --save

# yarn
yarn add honeybadger-js

You can include honeybadger-js from the node_modules directory.

Browserify/Webpack (CommonJS)

var Honeybadger = require("path/to/honeybadger");
Honeybadger.configure({
  apiKey: 'project api key',
  environment: 'production',
  revision: 'git SHA/project version'
});

RequireJS (AMD)

requirejs(["path/to/honeybadger"], function(Honeybadger) {
  Honeybadger.configure({
    apiKey: 'project api key',
    environment: 'production',
    revision: 'git SHA/project version'
  });
});

Rails Assets

Add the following to your Gemfile:

# Note: Requires bundler >= 1.8.4.
source 'https://rails-assets.org' do
  gem 'rails-assets-honeybadger'
end

Then add the following to application.js:

//= require honeybadger

Honeybadger.configure({
  apiKey: 'project api key',
  environment: 'production',
  revision: 'git SHA/project version'
});

Reporting Errors

By default Honeybadger will report all uncaught exceptions automatically using our window.onerror handler.

You can also manually notify Honeybadger of errors and other events in your application code:

try {
  // ...error producing code...
} catch(error) {
  Honeybadger.notify(error);
}

Identifying Users

Honeybadger can track what users have encountered each error. To identify the current user in error reports, add a user identifier and/or email address with Honeybadger.context:

Honeybadger.setContext({
  user_id: 123,
  user_email: 'user@example.com'
});

Tracking Deploys

Honeybadger can also keep track of application deployments, and link errors to the version which the error occurred in. Here's a simple curl script to record a deployment:

HONEYBADGER_ENV="production" \
HONEYBADGER_REVISION="git SHA/project version" \
HONEYBADGER_API_KEY="project api key" \
  curl -g "https://api.honeybadger.io/v1/deploys?deploy[environment]=$HONEYBADGER_ENV&deploy[local_username]=$USER&deploy[revision]=$HONEYBADGER_REVISION&api_key=$HONEYBADGER_API_KEY"

Be sure that the same revision is also configured in the honeybadger-js library. Read more about deploy tracking in the API docs.

Source Map Support

Honeybadger can automatically un-minify your code if you provide a source map along with your minified JavaScript files. Learn more about source maps.