Skip to content

Instantly share code, notes, and snippets.

@jmshal
Created June 18, 2014 08:57
Show Gist options
  • Save jmshal/dc7dbd75dfbb4a834713 to your computer and use it in GitHub Desktop.
Save jmshal/dc7dbd75dfbb4a834713 to your computer and use it in GitHub Desktop.
Bugsnag & Browserify
//
// **Bugsnag.js** is the official JavaScript notifier for
// [Bugsnag](https://bugsnag.com).
//
// Bugsnag gives you instant notification of errors and
// exceptions in your website's JavaScript code.
//
// Bugsnag.js is incredibly small, and has no external dependencies (not even
// jQuery!) so you can safely use it on any website.
//
// The `Bugsnag` object is the only globally exported variable
(function(definition) {
if (typeof exports === "object") {
exports = definition(global);
} else {
var old = window.Bugsnag;
window.Bugsnag = definition(window, old);
}
})(function (window, old) {
var self = {},
lastEvent,
lastScript,
previousNotification,
shouldCatch = true,
ignoreOnError = 0,
// We've seen cases where individual clients can infinite loop sending us errors
// (in some cases 10,000+ errors per page). This limit is at the point where
// you've probably learned everything useful there is to debug the problem,
// and we're happy to under-estimate the count to save the client (and Bugsnag's) resources.
eventsRemaining = 10;
// This is obsolete with CommonJS module loading, as we cannot assume the global
// scope is polluted with the Bugsnag object anyway. In this case, it's up to the
// host Javascript file to correctly utilise this functionality.
//
// Maybe it's worth removing all together, if the we're being loaded via CommonJS.
self.noConflict = function() {
window.Bugsnag = old;
return self;
};
//
// ### Manual error notification (public methods)
//
// #### Bugsnag.notifyException
//
// Notify Bugsnag about a given `exception`, typically that you've caught
// with a `try/catch` statement or that you've generated yourself.
//
// It's almost always better to let an exception bubble rather than catching
// it, as that gives more consistent behaviour across browsers. Consider
// re-throwing instead of calling .notifyException.
//
// Since most JavaScript exceptions use the `Error` class, we also allow
// you to provide a custom error name when calling `notifyException`.
//
// The default value is "warning" and "error" and "info" are also supported by the
// backend, all other values cause the notification to be dropped; and you
// will not see it in your dashboard.
self.notifyException = function (exception, name, metaData, severity) {
if (name && typeof name !== "string") {
metaData = name;
name = undefined;
}
if (!metaData) {
metaData = {};
}
addScriptToMetaData(metaData);
sendToBugsnag({
name: name || exception.name,
message: exception.message || exception.description,
stacktrace: stacktraceFromException(exception) || generateStacktrace(),
file: exception.fileName || exception.sourceURL,
lineNumber: exception.lineNumber || exception.line,
columnNumber: exception.columnNumber ? exception.columnNumber + 1 : undefined,
severity: severity || "warning"
}, metaData);
};
// #### Bugsnag.notify
//
// Notify Bugsnag about an error by passing in a `name` and `message`,
// without requiring an exception.
self.notify = function (name, message, metaData, severity) {
sendToBugsnag({
name: name,
message: message,
stacktrace: generateStacktrace(),
severity: severity || "warning"
}, metaData);
};
// Return a function acts like the given function, but reports
// any exceptions to Bugsnag before re-throwing them.
//
// This is not a public function because it can only be used if
// the exception is not caught after being thrown out of this function.
//
// If you call wrap twice on the same function, it'll give you back the
// same wrapped function. This lets removeEventListener to continue to
// work.
function wrap(_super, options) {
try {
if (typeof _super !== "function") {
return _super;
}
if (!_super.bugsnag) {
var currentScript = getCurrentScript();
_super.bugsnag = function (event) {
if (options && options.eventHandler) {
lastEvent = event;
}
lastScript = currentScript;
// We set shouldCatch to false on IE < 10 because catching the error ruins the file/line as reported in window.onerror,
// We set shouldCatch to false on Chrome/Safari because it interferes with "break on unhandled exception"
// All other browsers need shouldCatch to be true, as they don't pass the exception object to window.onerror
if (shouldCatch) {
try {
return _super.apply(this, arguments);
} catch (e) {
// We do this rather than stashing treating the error like lastEvent
// because in FF 26 onerror is not called for synthesized event handlers.
if (getSetting("autoNotify", true)) {
self.notifyException(e, null, null, "error");
ignoreNextOnError();
}
throw e;
} finally {
lastScript = null;
}
} else {
var ret = _super.apply(this, arguments);
// in case of error, this is set to null in window.onerror
lastScript = null;
return ret;
}
};
_super.bugsnag.bugsnag = _super.bugsnag;
}
return _super.bugsnag;
// This can happen if _super is not a normal javascript function.
// For example, see https://github.com/bugsnag/bugsnag-js/issues/28
} catch (e) {
return _super;
}
}
//
// ### Script tag tracking
//
// To emulate document.currentScript we use document.scripts.last.
// This only works while synchronous scripts are running, so we track
// that here.
var synchronousScriptsRunning = document.readyState !== "complete";
function loadCompleted() {
synchronousScriptsRunning = false;
}
// from jQuery. We don't have quite such tight bounds as they do if
// we end up on the window.onload event as we don't try and hack
// the .scrollLeft() fix in because it doesn't work in frames so
// we'd need these fallbacks anyway.
// The worst that can happen is we group an event handler that fires
// before us into the last script tag.
if (document.addEventListener) {
document.addEventListener("DOMContentLoaded", loadCompleted, true);
window.addEventListener("load", loadCompleted, true);
} else {
window.attachEvent("onload", loadCompleted);
}
function getCurrentScript() {
var script = document.currentScript || lastScript;
if (!script && synchronousScriptsRunning) {
var scripts = document.getElementsByTagName("script");
script = scripts[scripts.length - 1];
}
return script;
}
function addScriptToMetaData(metaData) {
var script = getCurrentScript();
if (script) {
metaData.script = {
src: script.src,
content: getSetting("inlineScript", true) ? script.innerHTML : ""
};
}
}
//
// ### Helpers & Setup
//
// Compile regular expressions upfront.
var API_KEY_REGEX = /^[0-9a-f]{32}$/i;
var FUNCTION_REGEX = /function\s*([\w\-$]+)?\s*\(/i;
// Set up default notifier settings.
var DEFAULT_BASE_ENDPOINT = "https://notify.bugsnag.com/";
var DEFAULT_NOTIFIER_ENDPOINT = DEFAULT_BASE_ENDPOINT + "js";
var NOTIFIER_VERSION = "2.3.5";
// Keep a reference to the currently executing script in the DOM.
// We'll use this later to extract settings from attributes.
var scripts = document.getElementsByTagName("script");
var thisScript = scripts[scripts.length - 1];
// Simple logging function that wraps `console.log` if available.
// This is useful for warning about configuration issues
// eg. forgetting to set an API key.
function log(msg) {
var console = window.console;
if (console !== undefined && console.log !== undefined) {
console.log("[Bugsnag] " + msg);
}
}
// Deeply serialize an object into a query string. We use the PHP-style
// nested object syntax, `nested[keys]=val`, to support heirachical
// objects. Similar to jQuery's `$.param` method.
function serialize(obj, prefix) {
var str = [];
for (var p in obj) {
if (obj.hasOwnProperty(p) && p != null && obj[p] != null) {
var k = prefix ? prefix + "[" + p + "]" : p, v = obj[p];
str.push(typeof v === "object" ? serialize(v, k) : encodeURIComponent(k) + "=" + encodeURIComponent(v));
}
}
return str.join("&");
}
// Deep-merge the `source` object into the `target` object and return
// the `target`. Properties in source that will overwrite those in target.
// Similar to jQuery's `$.extend` method.
function merge(target, source) {
if (source == null) {
return target;
}
target = target || {};
for (var key in source) {
if (source.hasOwnProperty(key)) {
try {
if (source[key].constructor === Object) {
target[key] = merge(target[key], source[key]);
} else {
target[key] = source[key];
}
} catch (e) {
target[key] = source[key];
}
}
}
return target;
}
// Make a HTTP request with given `url` and `params` object.
// For maximum browser compatibility and cross-domain support, requests are
// made by creating a temporary JavaScript `Image` object.
function request(url, params) {
if (typeof BUGSNAG_TESTING !== "undefined" && self.testRequest) {
self.testRequest(url, params);
} else {
var img = new Image();
img.src = url + "?" + serialize(params) + "&ct=img&cb=" + new Date().getTime();
}
}
// Extract all `data-*` attributes from a DOM element and return them as an
// object. This is used to allow Bugsnag settings to be set via attributes
// on the `script` tag, eg. `<script data-apikey="xyz">`.
// Similar to jQuery's `$(el).data()` method.
function getData(node) {
var dataAttrs = {};
var dataRegex = /^data\-([\w\-]+)$/;
var attrs = node.attributes;
for (var i = 0; i < attrs.length; i++) {
var attr = attrs[i];
if (dataRegex.test(attr.nodeName)) {
var key = attr.nodeName.match(dataRegex)[1];
dataAttrs[key] = attr.nodeValue;
}
}
return dataAttrs;
}
// Get configuration settings from either `self` (the `Bugsnag` object)
// or `data` (the `data-*` attributes).
var data;
function getSetting(name, fallback) {
data = data || getData(thisScript);
var setting = self[name] !== undefined ? self[name] : data[name.toLowerCase()];
if (setting === "false") {
setting = false;
}
return setting !== undefined ? setting : fallback;
}
// Validate a Bugsnag API key exists and is of the correct format.
function validateApiKey(apiKey) {
if (apiKey == null || !apiKey.match(API_KEY_REGEX)) {
log("Invalid API key '" + apiKey + "'");
return false;
}
return true;
}
// Send an error to Bugsnag.
function sendToBugsnag(details, metaData) {
// Validate the configured API key.
var apiKey = getSetting("apiKey");
if (!validateApiKey(apiKey) || !eventsRemaining) {
return;
}
eventsRemaining -= 1;
// Check if we should notify for this release stage.
var releaseStage = getSetting("releaseStage");
var notifyReleaseStages = getSetting("notifyReleaseStages");
if (notifyReleaseStages) {
var shouldNotify = false;
for (var i = 0; i < notifyReleaseStages.length; i++) {
if (releaseStage === notifyReleaseStages[i]) {
shouldNotify = true;
break;
}
}
if (!shouldNotify) {
return;
}
}
// Don't send multiple copies of the same error.
// This fixes a problem when a client goes into an infinite loop,
// and starts wasting all their bandwidth sending messages to bugsnag.
var deduplicate = [details.name, details.message, details.stacktrace].join("|");
if (deduplicate === previousNotification) {
return;
} else {
previousNotification = deduplicate;
}
if (lastEvent) {
metaData = metaData || {};
metaData["Last Event"] = eventToMetaData(lastEvent);
}
// Merge the local and global `metaData`.
var mergedMetaData = merge(merge({}, getSetting("metaData")), metaData);
// Run any `beforeNotify` function
var beforeNotify = self.beforeNotify;
if (typeof(beforeNotify) === "function") {
var retVal = beforeNotify(details, mergedMetaData);
if (retVal === false) {
return;
}
}
// Make the request:
//
// - Work out which endpoint to send to.
// - Combine error information with other data such as
// user-agent and locale, `metaData` and settings.
// - Make the HTTP request.
var location = window.location;
request(getSetting("endpoint") || DEFAULT_NOTIFIER_ENDPOINT, {
notifierVersion: NOTIFIER_VERSION,
apiKey: apiKey,
projectRoot: getSetting("projectRoot") || location.protocol + "//" + location.host,
context: getSetting("context") || location.pathname,
userId: getSetting("userId"), // Deprecated, remove in v3
user: getSetting("user"),
metaData: mergedMetaData,
releaseStage: releaseStage,
appVersion: getSetting("appVersion"),
url: window.location.href,
userAgent: navigator.userAgent,
language: navigator.language || navigator.userLanguage,
severity: details.severity,
name: details.name,
message: details.message,
stacktrace: details.stacktrace,
file: details.file,
lineNumber: details.lineNumber,
columnNumber: details.columnNumber,
payloadVersion: "2"
});
}
// Generate a browser stacktrace (or approximation) from the current stack.
// This is used to add a stacktrace to `Bugsnag.notify` calls, and to add a
// stacktrace approximation where we can't get one from an exception.
function generateStacktrace() {
var stacktrace;
var MAX_FAKE_STACK_SIZE = 10;
var ANONYMOUS_FUNCTION_PLACEHOLDER = "[anonymous]";
// Try to generate a real stacktrace (most browsers, except IE9 and below).
try {
throw new Error("");
} catch (exception) {
stacktrace = stacktraceFromException(exception);
}
// Otherwise, build a fake stacktrace from the list of method names by
// looping through the list of functions that called this one (and skip
// whoever called us).
if (!stacktrace) {
var functionStack = [];
try {
var curr = arguments.callee.caller.caller;
while (curr && functionStack.length < MAX_FAKE_STACK_SIZE) {
var fn = FUNCTION_REGEX.test(curr.toString()) ? RegExp.$1 || ANONYMOUS_FUNCTION_PLACEHOLDER : ANONYMOUS_FUNCTION_PLACEHOLDER;
functionStack.push(fn);
curr = curr.caller;
}
} catch (e) {
log(e);
}
stacktrace = functionStack.join("\n");
}
// Tell the backend to ignore the first two lines in the stack-trace.
// generateStacktrace() + window.onerror,
// generateStacktrace() + notify,
// generateStacktrace() + notifyException
return "<generated>\n" + stacktrace;
}
// Get the stacktrace string from an exception
function stacktraceFromException(exception) {
return exception.stack || exception.backtrace || exception.stacktrace;
}
// Populate the event tab of meta-data.
function eventToMetaData(event) {
var tab = {
millisecondsAgo: new Date() - event.timeStamp,
type: event.type,
which: event.which,
target: targetToString(event.target)
};
return tab;
}
// Convert a DOM element into a string suitable for passing to Bugsnag.
function targetToString(target) {
if (target) {
var attrs = target.attributes;
if (attrs) {
var ret = "<" + target.nodeName.toLowerCase();
for (var i = 0; i < attrs.length; i++) {
if (attrs[i].value && attrs[i].value.toString() != "null") {
ret += " " + attrs[i].name + "=\"" + attrs[i].value + "\"";
}
}
return ret + ">";
} else {
// e.g. #document
return target.nodeName;
}
}
}
// If we've notified bugsnag of an exception in wrap, we don't want to
// re-notify when it hits window.onerror after we re-throw it.
function ignoreNextOnError() {
ignoreOnError += 1;
window.setTimeout(function () {
ignoreOnError -= 1;
});
}
// Disable catching on IE < 10 as it destroys stack-traces from generateStackTrace()
if (!window.atob) {
shouldCatch = false;
// Disable catching on browsers that support HTML5 ErrorEvents properly.
// This lets debug on unhandled exceptions work.
} else if (window.ErrorEvent) {
try {
if (new window.ErrorEvent("test").colno === 0) {
shouldCatch = false;
}
} catch(e){ }
}
//
// ### Polyfilling
//
// Add a polyFill to an object
function polyFill(obj, name, makeReplacement) {
var original = obj[name];
var replacement = makeReplacement(original);
obj[name] = replacement;
if (typeof BUGSNAG_TESTING !== "undefined" && window.undo) {
window.undo.push(function () {
obj[name] = original;
});
}
}
if (getSetting("autoNotify", true)) {
//
// ### Automatic error notification
//
// Attach to `window.onerror` events and notify Bugsnag when they happen.
// These are mostly js compile/parse errors, but on some browsers all
// "uncaught" exceptions will fire this event.
//
polyFill(window, "onerror", function (_super) {
// Keep a reference to any existing `window.onerror` handler
if (typeof BUGSNAG_TESTING !== "undefined") {
self._onerror = _super;
}
return function bugsnag(message, url, lineNo, charNo, exception) {
var shouldNotify = getSetting("autoNotify", true);
var metaData = {};
// IE 6+ support.
if (!charNo && window.event) {
charNo = window.event.errorCharacter;
}
addScriptToMetaData(metaData);
lastScript = null;
if (shouldNotify && !ignoreOnError) {
sendToBugsnag({
name: exception && exception.name || "window.onerror",
message: message,
file: url,
lineNumber: lineNo,
columnNumber: charNo,
stacktrace: (exception && stacktraceFromException(exception)) || generateStacktrace(),
severity: "error"
}, metaData);
}
if (typeof BUGSNAG_TESTING !== "undefined") {
_super = self._onerror;
}
// Fire the existing `window.onerror` handler, if one exists
if (_super) {
_super(message, url, lineNo, charNo, exception);
}
};
});
var hijackTimeFunc = function (_super) {
// Note, we don't do `_super.call` because that doesn't work on IE 8,
// luckily this is implicitly window so it just works everywhere.
//
// setTimout in all browsers except IE <9 allows additional parameters
// to be passed, so in order to support these without resorting to call/apply
// we need an extra layer of wrapping.
return function (f, t) {
if (typeof f === "function") {
f = wrap(f);
var args = Array.prototype.slice.call(arguments, 2);
return _super(function () {
f.apply(this, args);
}, t);
} else {
return _super(f, t);
}
};
};
polyFill(window, "setTimeout", hijackTimeFunc);
polyFill(window, "setInterval", hijackTimeFunc);
if (window.requestAnimationFrame) {
polyFill(window, "requestAnimationFrame", hijackTimeFunc);
}
if (window.setImmediate) {
polyFill(window, "setImmediate", function (_super) {
return function (f) {
var args = Array.prototype.slice.call(arguments);
args[0] = wrap(args[0]);
return _super.apply(this, args);
};
});
}
// EventTarget is all that's required in modern chrome/opera
// EventTarget + Window + ModalWindow is all that's required in modern FF (there are a few Moz prefixed ones that we're ignoring)
// The rest is a collection of stuff for Safari and IE 11. (Again ignoring a few MS and WebKit prefixed things)
"EventTarget Window Node ApplicationCache AudioTrackList ChannelMergerNode CryptoOperation EventSource FileReader HTMLUnknownElement IDBDatabase IDBRequest IDBTransaction KeyOperation MediaController MessagePort ModalWindow Notification SVGElementInstance Screen TextTrack TextTrackCue TextTrackList WebSocket WebSocketWorker Worker XMLHttpRequest XMLHttpRequestEventTarget XMLHttpRequestUpload".replace(/\w+/g, function (global) {
var prototype = window[global] && window[global].prototype;
if (prototype && prototype.hasOwnProperty && prototype.hasOwnProperty("addEventListener")) {
polyFill(prototype, "addEventListener", function (_super) {
return function (e, f, capture, secure) {
// HTML lets event-handlers be objects with a handlEvent function,
// we need to change f.handleEvent here, as self.wrap will ignore f.
if (f && f.handleEvent) {
f.handleEvent = wrap(f.handleEvent, {eventHandler: true});
}
return _super.call(this, e, wrap(f, {eventHandler: true}), capture, secure);
};
});
// We also need to hack removeEventListener so that you can remove any
// event listeners.
polyFill(prototype, "removeEventListener", function (_super) {
return function (e, f, capture, secure) {
_super.call(this, e, f, capture, secure);
return _super.call(this, e, wrap(f), capture, secure);
};
});
}
});
}
return self;
});
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
!function(a,b){if("object"==typeof exports)exports=b(a);else{var c=window.Bugsnag;window.Bugsnag=b(window,c)}}(function(a,b){function c(a,b){try{if("function"!=typeof a)return a;if(!a.bugsnag){var c=e();a.bugsnag=function(d){if(b&&b.eventHandler&&(u=d),v=c,!y){var e=a.apply(this,arguments);return v=null,e}try{return a.apply(this,arguments)}catch(f){throw l("autoNotify",!0)&&(x.notifyException(f,null,null,"error"),s()),f}finally{v=null}},a.bugsnag.bugsnag=a.bugsnag}return a.bugsnag}catch(d){return a}}function d(){B=!1}function e(){var a=document.currentScript||v;if(!a&&B){var b=document.getElementsByTagName("script");a=b[b.length-1]}return a}function f(a){var b=e();b&&(a.script={src:b.src,content:l("inlineScript",!0)?b.innerHTML:""})}function g(b){var c=a.console;void 0!==c&&void 0!==c.log&&c.log("[Bugsnag] "+b)}function h(a,b){var c=[];for(var d in a)if(a.hasOwnProperty(d)&&null!=d&&null!=a[d]){var e=b?b+"["+d+"]":d,f=a[d];c.push("object"==typeof f?h(f,e):encodeURIComponent(e)+"="+encodeURIComponent(f))}return c.join("&")}function i(a,b){if(null==b)return a;a=a||{};for(var c in b)if(b.hasOwnProperty(c))try{a[c]=b[c].constructor===Object?i(a[c],b[c]):b[c]}catch(d){a[c]=b[c]}return a}function j(a,b){var c=new Image;c.src=a+"?"+h(b)+"&ct=img&cb="+(new Date).getTime()}function k(a){for(var b={},c=/^data\-([\w\-]+)$/,d=a.attributes,e=0;e<d.length;e++){var f=d[e];if(c.test(f.nodeName)){var g=f.nodeName.match(c)[1];b[g]=f.nodeValue}}return b}function l(a,b){C=C||k(J);var c=void 0!==x[a]?x[a]:C[a.toLowerCase()];return"false"===c&&(c=!1),void 0!==c?c:b}function m(a){return null!=a&&a.match(D)?!0:(g("Invalid API key '"+a+"'"),!1)}function n(b,c){var d=l("apiKey");if(m(d)&&A){A-=1;var e=l("releaseStage"),f=l("notifyReleaseStages");if(f){for(var g=!1,h=0;h<f.length;h++)if(e===f[h]){g=!0;break}if(!g)return}var k=[b.name,b.message,b.stacktrace].join("|");if(k!==w){w=k,u&&(c=c||{},c["Last Event"]=q(u));var n=i(i({},l("metaData")),c),o=x.beforeNotify;if("function"==typeof o){var p=o(b,n);if(p===!1)return}var r=a.location;j(l("endpoint")||G,{notifierVersion:H,apiKey:d,projectRoot:l("projectRoot")||r.protocol+"//"+r.host,context:l("context")||r.pathname,userId:l("userId"),user:l("user"),metaData:n,releaseStage:e,appVersion:l("appVersion"),url:a.location.href,userAgent:navigator.userAgent,language:navigator.language||navigator.userLanguage,severity:b.severity,name:b.name,message:b.message,stacktrace:b.stacktrace,file:b.file,lineNumber:b.lineNumber,columnNumber:b.columnNumber,payloadVersion:"2"})}}}function o(){var a,b=10,c="[anonymous]";try{throw new Error("")}catch(d){a=p(d)}if(!a){var e=[];try{for(var f=arguments.callee.caller.caller;f&&e.length<b;){var h=E.test(f.toString())?RegExp.$1||c:c;e.push(h),f=f.caller}}catch(i){g(i)}a=e.join("\n")}return"<generated>\n"+a}function p(a){return a.stack||a.backtrace||a.stacktrace}function q(a){var b={millisecondsAgo:new Date-a.timeStamp,type:a.type,which:a.which,target:r(a.target)};return b}function r(a){if(a){var b=a.attributes;if(b){for(var c="<"+a.nodeName.toLowerCase(),d=0;d<b.length;d++)b[d].value&&"null"!=b[d].value.toString()&&(c+=" "+b[d].name+'="'+b[d].value+'"');return c+">"}return a.nodeName}}function s(){z+=1,a.setTimeout(function(){z-=1})}function t(a,b,c){var d=a[b],e=c(d);a[b]=e}var u,v,w,x={},y=!0,z=0,A=10;x.noConflict=function(){return a.Bugsnag=b,x},x.notifyException=function(a,b,c,d){b&&"string"!=typeof b&&(c=b,b=void 0),c||(c={}),f(c),n({name:b||a.name,message:a.message||a.description,stacktrace:p(a)||o(),file:a.fileName||a.sourceURL,lineNumber:a.lineNumber||a.line,columnNumber:a.columnNumber?a.columnNumber+1:void 0,severity:d||"warning"},c)},x.notify=function(a,b,c,d){n({name:a,message:b,stacktrace:o(),severity:d||"warning"},c)};var B="complete"!==document.readyState;document.addEventListener?(document.addEventListener("DOMContentLoaded",d,!0),a.addEventListener("load",d,!0)):a.attachEvent("onload",d);var C,D=/^[0-9a-f]{32}$/i,E=/function\s*([\w\-$]+)?\s*\(/i,F="https://notify.bugsnag.com/",G=F+"js",H="2.3.5",I=document.getElementsByTagName("script"),J=I[I.length-1];if(a.atob){if(a.ErrorEvent)try{0===new a.ErrorEvent("test").colno&&(y=!1)}catch(K){}}else y=!1;if(l("autoNotify",!0)){t(a,"onerror",function(b){return function(c,d,e,g,h){var i=l("autoNotify",!0),j={};!g&&a.event&&(g=a.event.errorCharacter),f(j),v=null,i&&!z&&n({name:h&&h.name||"window.onerror",message:c,file:d,lineNumber:e,columnNumber:g,stacktrace:h&&p(h)||o(),severity:"error"},j),b&&b(c,d,e,g,h)}});var L=function(a){return function(b,d){if("function"==typeof b){b=c(b);var e=Array.prototype.slice.call(arguments,2);return a(function(){b.apply(this,e)},d)}return a(b,d)}};t(a,"setTimeout",L),t(a,"setInterval",L),a.requestAnimationFrame&&t(a,"requestAnimationFrame",L),a.setImmediate&&t(a,"setImmediate",function(a){return function(){var b=Array.prototype.slice.call(arguments);return b[0]=c(b[0]),a.apply(this,b)}}),"EventTarget Window Node ApplicationCache AudioTrackList ChannelMergerNode CryptoOperation EventSource FileReader HTMLUnknownElement IDBDatabase IDBRequest IDBTransaction KeyOperation MediaController MessagePort ModalWindow Notification SVGElementInstance Screen TextTrack TextTrackCue TextTrackList WebSocket WebSocketWorker Worker XMLHttpRequest XMLHttpRequestEventTarget XMLHttpRequestUpload".replace(/\w+/g,function(b){var d=a[b]&&a[b].prototype;d&&d.hasOwnProperty&&d.hasOwnProperty("addEventListener")&&(t(d,"addEventListener",function(a){return function(b,d,e,f){return d&&d.handleEvent&&(d.handleEvent=c(d.handleEvent,{eventHandler:!0})),a.call(this,b,c(d,{eventHandler:!0}),e,f)}}),t(d,"removeEventListener",function(a){return function(b,d,e,f){return a.call(this,b,d,e,f),a.call(this,b,c(d),e,f)}}))})}return x});
},{}],2:[function(require,module,exports){
var bugsnag = require('./bugsnag.js');
console.log(bugsnag); // undefined
},{"./bugsnag.js":1}]},{},[2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment