3163 lines · 92.3 KB · JavaScript
RawDownload
/*! Raven.js 3.20.1 (42adaf5) | github.com/getsentry/raven-js */ /* * Includes TraceKit * https://github.com/getsentry/TraceKit * * Copyright 2017 Matt Robenolt and other contributors * Released under the BSD license * https://github.com/getsentry/raven-js/blob/master/LICENSE * */ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Raven = f()}})(function(){var define,module,exports;return (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);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.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(_dereq_,module,exports){function RavenConfigError(message) {  this.name = 'RavenConfigError';  this.message = message;}RavenConfigError.prototype = new Error();RavenConfigError.prototype.constructor = RavenConfigError; module.exports = RavenConfigError; },{}],2:[function(_dereq_,module,exports){var wrapMethod = function(console, level, callback) {  var originalConsoleLevel = console[level];  var originalConsole = console;   if (!(level in console)) {    return;  }   var sentryLevel = level === 'warn' ? 'warning' : level;   console[level] = function() {    var args = [].slice.call(arguments);     var msg = '' + args.join(' ');    var data = {level: sentryLevel, logger: 'console', extra: {arguments: args}};     if (level === 'assert') {      if (args[0] === false) {        // Default browsers message        msg = 'Assertion failed: ' + (args.slice(1).join(' ') || 'console.assert');        data.extra.arguments = args.slice(1);        callback && callback(msg, data);      }    } else {      callback && callback(msg, data);    }     // this fails for some browsers. :(    if (originalConsoleLevel) {      // IE9 doesn't allow calling apply on console functions directly      // See: https://stackoverflow.com/questions/5472938/does-ie9-support-console-log-and-is-it-a-real-function#answer-5473193      Function.prototype.apply.call(originalConsoleLevel, originalConsole, args);    }  };}; module.exports = {  wrapMethod: wrapMethod}; },{}],3:[function(_dereq_,module,exports){(function (global){/*global XDomainRequest:false */ var TraceKit = _dereq_(6);var stringify = _dereq_(7);var RavenConfigError = _dereq_(1); var utils = _dereq_(5);var isError = utils.isError;var isObject = utils.isObject;var isErrorEvent = utils.isErrorEvent;var isUndefined = utils.isUndefined;var isFunction = utils.isFunction;var isString = utils.isString;var isArray = utils.isArray;var isEmptyObject = utils.isEmptyObject;var each = utils.each;var objectMerge = utils.objectMerge;var truncate = utils.truncate;var objectFrozen = utils.objectFrozen;var hasKey = utils.hasKey;var joinRegExp = utils.joinRegExp;var urlencode = utils.urlencode;var uuid4 = utils.uuid4;var htmlTreeAsString = utils.htmlTreeAsString;var isSameException = utils.isSameException;var isSameStacktrace = utils.isSameStacktrace;var parseUrl = utils.parseUrl;var fill = utils.fill; var wrapConsoleMethod = _dereq_(2).wrapMethod; var dsnKeys = 'source protocol user pass host port path'.split(' '),  dsnPattern = /^(?:(\w+):)?\/\/(?:(\w+)(:\w+)?@)?([\w\.-]+)(?::(\d+))?(\/.*)/; function now() {  return +new Date();} // This is to be defensive in environments where window does not exist (see https://github.com/getsentry/raven-js/pull/785)var _window =  typeof window !== 'undefined'    ? window    : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};var _document = _window.document;var _navigator = _window.navigator; function keepOriginalCallback(original, callback) {  return isFunction(callback)    ? function(data) {        return callback(data, original);      }    : callback;} // First, check for JSON support// If there is no JSON, we no-op the core features of Raven// since JSON is required to encode the payloadfunction Raven() {  this._hasJSON = !!(typeof JSON === 'object' && JSON.stringify);  // Raven can run in contexts where there's no document (react-native)  this._hasDocument = !isUndefined(_document);  this._hasNavigator = !isUndefined(_navigator);  this._lastCapturedException = null;  this._lastData = null;  this._lastEventId = null;  this._globalServer = null;  this._globalKey = null;  this._globalProject = null;  this._globalContext = {};  this._globalOptions = {    logger: 'javascript',    ignoreErrors: [],    ignoreUrls: [],    whitelistUrls: [],    includePaths: [],    collectWindowErrors: true,    maxMessageLength: 0,     // By default, truncates URL values to 250 chars    maxUrlLength: 250,    stackTraceLimit: 50,    autoBreadcrumbs: true,    instrument: true,    sampleRate: 1  };  this._ignoreOnError = 0;  this._isRavenInstalled = false;  this._originalErrorStackTraceLimit = Error.stackTraceLimit;  // capture references to window.console *and* all its methods first  // before the console plugin has a chance to monkey patch  this._originalConsole = _window.console || {};  this._originalConsoleMethods = {};  this._plugins = [];  this._startTime = now();  this._wrappedBuiltIns = [];  this._breadcrumbs = [];  this._lastCapturedEvent = null;  this._keypressTimeout;  this._location = _window.location;  this._lastHref = this._location && this._location.href;  this._resetBackoff();   // eslint-disable-next-line guard-for-in  for (var method in this._originalConsole) {    this._originalConsoleMethods[method] = this._originalConsole[method];  }} /* * The core Raven singleton * * @this {Raven} */ Raven.prototype = {  // Hardcode version string so that raven source can be loaded directly via  // webpack (using a build step causes webpack #1617). Grunt verifies that  // this value matches package.json during build.  //   See: https://github.com/getsentry/raven-js/issues/465  VERSION: '3.20.1',   debug: false,   TraceKit: TraceKit, // alias to TraceKit   /*     * Configure Raven with a DSN and extra options     *     * @param {string} dsn The public Sentry DSN     * @param {object} options Set of global options [optional]     * @return {Raven}     */  config: function(dsn, options) {    var self = this;     if (self._globalServer) {      this._logDebug('error', 'Error: Raven has already been configured');      return self;    }    if (!dsn) return self;     var globalOptions = self._globalOptions;     // merge in options    if (options) {      each(options, function(key, value) {        // tags and extra are special and need to be put into context        if (key === 'tags' || key === 'extra' || key === 'user') {          self._globalContext[key] = value;        } else {          globalOptions[key] = value;        }      });    }     self.setDSN(dsn);     // "Script error." is hard coded into browsers for errors that it can't read.    // this is the result of a script being pulled in from an external domain and CORS.    globalOptions.ignoreErrors.push(/^Script error\.?$/);    globalOptions.ignoreErrors.push(/^Javascript error: Script error\.? on line 0$/);     // join regexp rules into one big rule    globalOptions.ignoreErrors = joinRegExp(globalOptions.ignoreErrors);    globalOptions.ignoreUrls = globalOptions.ignoreUrls.length      ? joinRegExp(globalOptions.ignoreUrls)      : false;    globalOptions.whitelistUrls = globalOptions.whitelistUrls.length      ? joinRegExp(globalOptions.whitelistUrls)      : false;    globalOptions.includePaths = joinRegExp(globalOptions.includePaths);    globalOptions.maxBreadcrumbs = Math.max(      0,      Math.min(globalOptions.maxBreadcrumbs || 100, 100)    ); // default and hard limit is 100     var autoBreadcrumbDefaults = {      xhr: true,      console: true,      dom: true,      location: true,      sentry: true    };     var autoBreadcrumbs = globalOptions.autoBreadcrumbs;    if ({}.toString.call(autoBreadcrumbs) === '[object Object]') {      autoBreadcrumbs = objectMerge(autoBreadcrumbDefaults, autoBreadcrumbs);    } else if (autoBreadcrumbs !== false) {      autoBreadcrumbs = autoBreadcrumbDefaults;    }    globalOptions.autoBreadcrumbs = autoBreadcrumbs;     var instrumentDefaults = {      tryCatch: true    };     var instrument = globalOptions.instrument;    if ({}.toString.call(instrument) === '[object Object]') {      instrument = objectMerge(instrumentDefaults, instrument);    } else if (instrument !== false) {      instrument = instrumentDefaults;    }    globalOptions.instrument = instrument;     TraceKit.collectWindowErrors = !!globalOptions.collectWindowErrors;     // return for chaining    return self;  },   /*     * Installs a global window.onerror error handler     * to capture and report uncaught exceptions.     * At this point, install() is required to be called due     * to the way TraceKit is set up.     *     * @return {Raven}     */  install: function() {    var self = this;    if (self.isSetup() && !self._isRavenInstalled) {      TraceKit.report.subscribe(function() {        self._handleOnErrorStackInfo.apply(self, arguments);      });       self._patchFunctionToString();       if (self._globalOptions.instrument && self._globalOptions.instrument.tryCatch) {        self._instrumentTryCatch();      }       if (self._globalOptions.autoBreadcrumbs) self._instrumentBreadcrumbs();       // Install all of the plugins      self._drainPlugins();       self._isRavenInstalled = true;    }     Error.stackTraceLimit = self._globalOptions.stackTraceLimit;    return this;  },   /*     * Set the DSN (can be called multiple time unlike config)     *     * @param {string} dsn The public Sentry DSN     */  setDSN: function(dsn) {    var self = this,      uri = self._parseDSN(dsn),      lastSlash = uri.path.lastIndexOf('/'),      path = uri.path.substr(1, lastSlash);     self._dsn = dsn;    self._globalKey = uri.user;    self._globalSecret = uri.pass && uri.pass.substr(1);    self._globalProject = uri.path.substr(lastSlash + 1);     self._globalServer = self._getGlobalServer(uri);     self._globalEndpoint =      self._globalServer + '/' + path + 'api/' + self._globalProject + '/store/';     // Reset backoff state since we may be pointing at a    // new project/server    this._resetBackoff();  },   /*     * Wrap code within a context so Raven can capture errors     * reliably across domains that is executed immediately.     *     * @param {object} options A specific set of options for this context [optional]     * @param {function} func The callback to be immediately executed within the context     * @param {array} args An array of arguments to be called with the callback [optional]     */  context: function(options, func, args) {    if (isFunction(options)) {      args = func || [];      func = options;      options = undefined;    }     return this.wrap(options, func).apply(this, args);  },   /*     * Wrap code within a context and returns back a new function to be executed     *     * @param {object} options A specific set of options for this context [optional]     * @param {function} func The function to be wrapped in a new context     * @param {function} func A function to call before the try/catch wrapper [optional, private]     * @return {function} The newly wrapped functions with a context     */  wrap: function(options, func, _before) {    var self = this;    // 1 argument has been passed, and it's not a function    // so just return it    if (isUndefined(func) && !isFunction(options)) {      return options;    }     // options is optional    if (isFunction(options)) {      func = options;      options = undefined;    }     // At this point, we've passed along 2 arguments, and the second one    // is not a function either, so we'll just return the second argument.    if (!isFunction(func)) {      return func;    }     // We don't wanna wrap it twice!    try {      if (func.__raven__) {        return func;      }       // If this has already been wrapped in the past, return that      if (func.__raven_wrapper__) {        return func.__raven_wrapper__;      }    } catch (e) {      // Just accessing custom props in some Selenium environments      // can cause a "Permission denied" exception (see raven-js#495).      // Bail on wrapping and return the function as-is (defers to window.onerror).      return func;    }     function wrapped() {      var args = [],        i = arguments.length,        deep = !options || (options && options.deep !== false);       if (_before && isFunction(_before)) {        _before.apply(this, arguments);      }       // Recursively wrap all of a function's arguments that are      // functions themselves.      while (i--) args[i] = deep ? self.wrap(options, arguments[i]) : arguments[i];       try {        // Attempt to invoke user-land function        // NOTE: If you are a Sentry user, and you are seeing this stack frame, it        //       means Raven caught an error invoking your application code. This is        //       expected behavior and NOT indicative of a bug with Raven.js.        return func.apply(this, args);      } catch (e) {        self._ignoreNextOnError();        self.captureException(e, options);        throw e;      }    }     // copy over properties of the old function    for (var property in func) {      if (hasKey(func, property)) {        wrapped[property] = func[property];      }    }    wrapped.prototype = func.prototype;     func.__raven_wrapper__ = wrapped;    // Signal that this function has been wrapped/filled already    // for both debugging and to prevent it to being wrapped/filled twice    wrapped.__raven__ = true;    wrapped.__orig__ = func;     return wrapped;  },   /*     * Uninstalls the global error handler.     *     * @return {Raven}     */  uninstall: function() {    TraceKit.report.uninstall();     this._unpatchFunctionToString();    this._restoreBuiltIns();     Error.stackTraceLimit = this._originalErrorStackTraceLimit;    this._isRavenInstalled = false;     return this;  },   /*     * Manually capture an exception and send it over to Sentry     *     * @param {error} ex An exception to be logged     * @param {object} options A specific set of options for this error [optional]     * @return {Raven}     */  captureException: function(ex, options) {    // Cases for sending ex as a message, rather than an exception    var isNotError = !isError(ex);    var isNotErrorEvent = !isErrorEvent(ex);    var isErrorEventWithoutError = isErrorEvent(ex) && !ex.error;     if ((isNotError && isNotErrorEvent) || isErrorEventWithoutError) {      return this.captureMessage(        ex,        objectMerge(          {            trimHeadFrames: 1,            stacktrace: true // if we fall back to captureMessage, default to attempting a new trace          },          options        )      );    }     // Get actual Error from ErrorEvent    if (isErrorEvent(ex)) ex = ex.error;     // Store the raw exception object for potential debugging and introspection    this._lastCapturedException = ex;     // TraceKit.report will re-raise any exception passed to it,    // which means you have to wrap it in try/catch. Instead, we    // can wrap it here and only re-raise if TraceKit.report    // raises an exception different from the one we asked to    // report on.    try {      var stack = TraceKit.computeStackTrace(ex);      this._handleStackInfo(stack, options);    } catch (ex1) {      if (ex !== ex1) {        throw ex1;

Lines 1–500 of 3163.