var TraceKit = require('../vendor/TraceKit/tracekit');
var stringify = require('../vendor/json-stringify-safe/stringify');
var md5 = require('../vendor/md5/md5');
var RavenConfigError = require('./configError');
var utils = require('./utils');
var isErrorEvent = utils.isErrorEvent;
var isDOMError = utils.isDOMError;
var isDOMException = utils.isDOMException;
var isError = utils.isError;
var isObject = utils.isObject;
var isPlainObject = utils.isPlainObject;
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 supportsFetch = utils.supportsFetch;
var supportsReferrerPolicy = utils.supportsReferrerPolicy;
var serializeKeysForMessage = utils.serializeKeysForMessage;
var serializeException = utils.serializeException;
var sanitize = utils.sanitize;
var wrapConsoleMethod = require('./console').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;
// 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 payload
function 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 = {
// SENTRY_RELEASE can be injected by https://github.com/getsentry/sentry-webpack-plugin
release: _window.SENTRY_RELEASE && _window.SENTRY_RELEASE.id,
logger: 'javascript',
ignoreErrors: [],
ignoreUrls: [],
whitelistUrls: [],
includePaths: [],
headers: null,
collectWindowErrors: true,
captureUnhandledRejections: true,
maxMessageLength: 0,
// By default, truncates URL values to 250 chars
maxUrlLength: 250,
stackTraceLimit: 50,
autoBreadcrumbs: true,
instrument: true,
sampleRate: 1,
sanitizeKeys: []
};
this._fetchDefaults = {
method: 'POST',
// Despite all stars in the sky saying that Edge supports old draft syntax, aka 'never', 'always', 'origin' and 'default
// https://caniuse.com/#feat=referrer-policy
// It doesn't. And it throw exception instead of ignoring this parameter...
// REF: https://github.com/getsentry/raven-js/issues/1233
referrerPolicy: supportsReferrerPolicy() ? 'origin' : ''
};
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.27.2',
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]
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
// 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 = {};
}
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} _before 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;
if (isErrorEvent(ex) && ex.error) {
// If it is an ErrorEvent with error property, extract it to get actual Error
ex = ex.error;
} else if (isDOMError(ex) || isDOMException(ex)) {
// If it is a DOMError or DOMException (which are legacy APIs, but still supported in some browsers)
// then we just extract the name and message, as they don't provide anything else
// https://developer.mozilla.org/en-US/docs/Web/API/DOMError
// https://developer.mozilla.org/en-US/docs/Web/API/DOMException
var name = ex.name || (isDOMError(ex) ? 'DOMError' : 'DOMException');
var message = ex.message ? name + ': ' + ex.message : name;
return this.captureMessage(
message,
objectMerge(options, {
// neither DOMError or DOMException provide stack trace and we most likely wont get it this way as well
// but it's barely any overhead so we may at least try
stacktrace: true,
trimHeadFrames: options.trimHeadFrames + 1
})
);
} else if (isError(ex)) {
// we have a real Error object
ex = ex;
} else if (isPlainObject(ex)) {
// If it is plain Object, serialize it manually and extract options
// This will allow us to group events based on top-level keys
// which is much better than creating new group when any key/value change
options = this._getCaptureExceptionOptionsFromPlainObject(options, ex);
ex = new Error(options.message);
} else {
// If none of previous checks were valid, then it means that
// it's not a DOMError/DOMException
// it's not a plain Object
// it's not a valid ErrorEvent (one with an error property)
// it's not an Error
// So bail out and capture it as a simple message:
return this.captureMessage(
ex,
objectMerge(options, {
stacktrace: true, // if we fall back to captureMessage, default to attempting a new trace
trimHeadFrames: options.trimHeadFrames + 1
})
);
}
// 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;
}
}
@param {string} msg A plain message to be captured in Sentry
@param {object} options A specific set of options for this message [optional]
@return {Raven}
*/
captureMessage: function(msg, options) {
// config() automagically converts ignoreErrors from a list to a RegExp so we need to test for an
// early call; we'll error on the side of logging anything called before configuration since it's
// probably something you should see:
if (
!!this._globalOptions.ignoreErrors.test &&
this._globalOptions.ignoreErrors.test(msg)
) {
return;
}
options = options || {};
msg = msg + ''; // Make sure it's actually a string
var data = objectMerge(
{
message: msg
},
options
);
var ex;
// Generate a "synthetic" stack trace from this point.
// NOTE: If you are a Sentry user, and you are seeing this stack frame, it is NOT indicative
// of a bug with Raven.js. Sentry generates synthetic traces either by configuration,
// or if it catches a thrown object without a "stack" property.
try {
throw new Error(msg);
} catch (ex1) {
ex = ex1;
}
// null exception name so Error isn't prefixed to msg
ex.name = null;
var stack = TraceKit.computeStackTrace(ex);
// stack[0] is throw new Error(msg) call itself, we are interested in the frame that was just before that, stack[1]
var initialCall = isArray(stack.stack) && stack.stack[1];
// if stack[1] is Raven.captureException, it means that someone passed a string to it and we redirected that call
// to be handled by captureMessage, thus initialCall is the 3rd one, not 2nd
// initialCall => captureException(string) => captureMessage(string)
if (initialCall && initialCall.func === 'Raven.captureException') {
initialCall = stack.stack[2];
}
var fileurl = (initialCall && initialCall.url) || '';
if (
!!this._globalOptions.ignoreUrls.test &&
this._globalOptions.ignoreUrls.test(fileurl)
) {
return;
}
if (
!!this._globalOptions.whitelistUrls.test &&
!this._globalOptions.whitelistUrls.test(fileurl)
) {
return;
}
// Always attempt to get stacktrace if message is empty.
// It's the only way to provide any helpful information to the user.
if (this._globalOptions.stacktrace || options.stacktrace || data.message === '') {
// fingerprint on msg, not stack trace (legacy behavior, could be revisited)
data.fingerprint = data.fingerprint == null ? msg : data.fingerprint;
options = objectMerge(
{
trimHeadFrames: 0
},
options
);
// Since we know this is a synthetic trace, the top frame (this function call)
// MUST be from Raven.js, so mark it for trimming
// We add to the trim counter so that callers can choose to trim extra frames, such
// as utility functions.
options.trimHeadFrames += 1;
var frames = this._prepareFrames(stack, options);
data.stacktrace = {
// Sentry expects frames oldest to newest
frames: frames.reverse()
};
}
// Make sure that fingerprint is always wrapped in an array
if (data.fingerprint) {
data.fingerprint = isArray(data.fingerprint)
? data.fingerprint
: [data.fingerprint];
}
this._plugins.push([plugin, pluginArgs]);
if (this._isRavenInstalled) {
this._drainPlugins();
}
return this;
},
/*
Set/clear a user to be sent along with the payload.
@param {object} user An object representing user data [optional]
@return {Raven}
*/
setUserContext: function(user) {
// Intentionally do not merge here since that's an unexpected behavior.
this._globalContext.user = user;
return this;
},
/*
Merge extra attributes to be sent along with the payload.
@param {object} extra An object representing extra data [optional]
// Attempt to initialize Raven on load
var RavenConfig = _window.RavenConfig;
if (RavenConfig) {
this.config(RavenConfig.dsn, RavenConfig.config).install();
}
},
showReportDialog: function(options) {
if (
!_document // doesn't work without a document (React native)
)
return;
I got this error few times. You need to delete XDCpay and install again and put your seed key.
`..
256320 256321 256322 256323 256324 256325 256326 256327 256328 256329 256330 256331 256332 256333 256334 256335 256336 256337 256338 256339 256340 256341 256342 256343 256344 256345 256346 256347 256348 256349 256350 256351 256352 256353 256354 256355 256356 256357 256358 256359 256360 256361 256362 256363 256364 256365 256366 256367 256368 256369 256370 256371 256372 256373 256374 256375 256376 256377 256378 256379 256380 256381 256382 256383 256384 256385 256386 256387 256388 256389 256390 256391 256392 256393 256394 256395 256396 256397 256398 256399 256400 256401 256402 256403 256404 256405 256406 256407 256408 256409 256410 256411 256412 256413 256414 256415 256416 256417 256418 256419 256420 256421 256422 256423 256424 256425 256426 256427 256428 256429 256430 256431 256432 256433 256434 256435 256436 256437 256438 256439 256440 256441 256442 256443 256444 256445 256446 256447 256448 256449 256450 256451 256452 256453 256454 256455 256456 256457 256458 256459 256460 256461 256462 256463 256464 256465 256466 256467 256468 256469 256470 256471 256472 256473 256474 256475 256476 256477 256478 256479 256480 256481 256482 256483 256484 256485 256486 256487 256488 256489 256490 256491 256492 256493 256494 256495 256496 256497 256498 256499 256500 256501 256502 256503 256504 256505 256506 256507 256508 256509 256510 256511 256512 256513 256514 256515 256516 256517 256518 256519 256520 256521 256522 256523 256524 256525 256526 256527 256528 256529 256530 256531 256532 256533 256534 256535 256536 256537 256538 256539 256540 256541 256542 256543 256544 256545 256546 256547 256548 256549 256550 256551 256552 256553 256554 256555 256556 256557 256558 256559 256560 256561 256562 256563 256564 256565 256566 256567 256568 256569 256570 256571 256572 256573 256574 256575 256576 256577 256578 256579 256580 256581 256582 256583 256584 256585 256586 256587 256588 256589 256590 256591 256592 256593 256594 256595 256596 256597 256598 256599 256600 256601 256602 256603 256604 256605 256606 256607 256608 256609 256610 256611 256612 256613 256614 256615 256616 256617 256618 256619 256620 256621 256622 256623 256624 256625 256626 256627 256628 256629 256630 256631 256632 256633 256634 256635 256636 256637 256638 256639 256640 256641 256642 256643 256644 256645 256646 256647 256648 256649 256650 256651 256652 256653 256654 256655 256656 256657 256658 256659 256660 256661 256662 256663 256664 256665 256666 256667 256668 256669 256670 256671 256672 256673 256674 256675 256676 256677 256678 256679 256680 256681 256682 256683 256684 256685 256686 256687 256688 256689 256690 256691 256692 256693 256694 256695 256696 256697 256698 256699 256700 256701 256702 256703 256704 256705 256706 256707 256708 256709 256710 256711 256712 256713 256714 256715 256716 256717 256718 256719 256720 256721 256722 256723 256724 256725 256726 256727 256728 256729 256730 256731 256732 256733 256734 256735 256736 256737 256738 256739 256740 256741 256742 256743 256744 256745 256746 256747 256748 256749 256750 256751 256752 256753 256754 256755 256756 256757 256758 256759 256760 256761 256762 256763 256764 256765 256766 256767 256768 256769 256770 256771 256772 256773 256774 256775 256776 256777 256778 256779 256780 256781 256782 256783 256784 256785 256786 256787 256788 256789 256790 256791 256792 256793 256794 256795 256796 256797 256798 256799 256800 256801 256802 256803 256804 256805 256806 256807 256808 256809 256810 256811 256812 256813 256814 256815 256816 256817 256818 256819 256820 256821 256822 256823 256824 256825 256826 256827 256828 256829 256830 256831 256832 256833 256834 256835 256836 256837 256838 256839 256840 256841 256842 256843 256844 256845 256846 256847 256848 256849 256850 256851 256852 256853 256854 256855 256856 256857 256858 256859 256860 256861 256862 256863 256864 256865 256866 256867 256868 256869 256870 256871 256872 256873 256874 256875 256876 256877 256878 256879 256880 256881 256882 256883 256884 256885 256886 256887 256888 256889 256890 256891 256892 256893 256894 256895 256896 256897 256898 256899 256900 256901 256902 256903 256904 256905 256906 256907 256908 256909 256910 256911 256912 256913 256914 256915 256916 256917 256918 256919 256920 256921 256922 256923 256924 256925 256926 256927 256928 256929 256930 256931 256932 256933 256934 256935 256936 256937 256938 256939 256940 256941 256942 256943 256944 256945 256946 256947 256948 256949 256950 256951 256952 256953 256954 256955 256956 256957 256958 256959 256960 256961 256962 256963 256964 256965 256966 256967 256968 256969 256970 256971 256972 256973 256974 256975 256976 256977 256978 256979 256980 256981 256982 256983 256984 256985 256986 256987 256988 256989 256990 256991 256992 256993 256994 256995 256996 256997 256998 256999 257000 257001 257002 257003 257004 257005 257006 257007 257008 257009 257010 257011 257012 257013 257014 257015 257016 257017 257018 257019 257020 257021 257022 257023 257024 257025 257026 257027 257028 257029 257030 257031 257032 257033 257034 257035 257036 257037 257038 257039 257040 257041 257042 257043 257044 257045 257046 257047 257048 257049 257050 257051 257052 257053 257054 257055 257056 257057 257058 257059 257060 257061 257062 257063 257064 257065 257066 257067 257068 257069 257070 257071 257072 257073 257074 257075 257076 257077 257078 257079 257080 257081 257082 257083 257084 257085 257086 257087 257088 257089 257090 257091 257092 257093 257094 257095 257096 257097 257098 257099 257100 257101 257102 257103 257104 257105 257106 257107 257108 257109 257110 257111 257112 257113 257114 257115 257116 257117 257118 257119 257120 257121 257122 257123 257124 257125 257126 257127 257128 257129 257130 257131 257132 257133 257134 257135 257136 257137 257138 257139 257140 257141 257142 257143 257144 257145 257146 257147 257148 257149 257150 257151 257152 257153 257154 257155 257156 257157 257158 257159 257160 257161 257162 257163 257164 257165 257166 257167 257168 257169 257170 257171 257172 257173 257174 257175 257176 257177 257178 257179 257180 257181 257182 257183 257184 257185 257186 257187 257188 257189 257190 257191 257192 257193 257194 257195 257196 257197 257198 257199 257200 257201 257202 257203 257204 257205 257206 257207 257208 257209 257210 257211 257212 257213 257214 257215 257216 257217 257218 257219 257220 257221 257222 257223 257224 257225 257226 257227 257228 257229 257230 257231 257232 257233 257234 257235 257236 257237 257238 257239 257240 257241 257242 257243 257244 257245 257246 257247 257248 257249 257250 257251 257252 257253 257254 257255 257256 257257 257258 257259 257260 257261 257262 257263 257264 257265 257266 257267 257268 257269 257270 257271 257272 257273 257274 257275 257276 257277 257278 257279 257280 257281 257282 257283 257284 257285 257286 257287 257288 257289 257290 257291 257292 257293 257294 257295 257296 257297 257298 257299 257300 257301 257302 257303 257304 257305 257306 257307 257308 257309 257310 257311 257312 257313 257314 257315 257316 257317 257318 ... [[getLinesNotShownLabel( truncatedBefore, '', '')]] throw new TypeError('"buf" argument must be a Buffer or Uint8Array') }
if (typeof offset === 'function') { cb = offset offset = 0 size = buf.length } else if (typeof size === 'function') { cb = size size = buf.length - offset } else if (typeof cb !== 'function') { throw new TypeError('"cb" argument must be a function') } assertOffset(offset, buf.length) assertSize(size, offset, buf.length) return actualFill(buf, offset, size, cb) }
function actualFill (buf, offset, size, cb) { if (process.browser) { var ourBuf = buf.buffer var uint = new Uint8Array(ourBuf, offset, size) crypto.getRandomValues(uint) if (cb) { process.nextTick(function () { cb(null, buf) }) return } return buf } if (cb) { randombytes(size, function (err, bytes) { if (err) { return cb(err) } bytes.copy(buf, offset) cb(null, buf) }) return } var bytes = randombytes(size) bytes.copy(buf, offset) return buf } function randomFillSync (buf, offset, size) { if (typeof offset === 'undefined') { offset = 0 } if (!Buffer.isBuffer(buf) && !(buf instanceof global.Uint8Array)) { throw new TypeError('"buf" argument must be a Buffer or Uint8Array') }
assertOffset(offset, buf.length)
if (size === undefined) size = buf.length - offset
assertSize(size, offset, buf.length)
return actualFill(buf, offset, size) }
}).call(this)}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"_process":756,"randombytes":1842,"safe-buffer":2239}],1844:[function(require,module,exports){ function RavenConfigError(message) { this.name = 'RavenConfigError'; this.message = message; } RavenConfigError.prototype = new Error(); RavenConfigError.prototype.constructor = RavenConfigError;
module.exports = RavenConfigError;
},{}],1845:[function(require,module,exports){ var utils = require('./utils');
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);
}; };
module.exports = { wrapMethod: wrapMethod };
},{"./utils":1848}],1846:[function(require,module,exports){ (function (global){(function (){ /global XDomainRequest:false /
var TraceKit = require('../vendor/TraceKit/tracekit'); var stringify = require('../vendor/json-stringify-safe/stringify'); var md5 = require('../vendor/md5/md5'); var RavenConfigError = require('./configError');
var utils = require('./utils'); var isErrorEvent = utils.isErrorEvent; var isDOMError = utils.isDOMError; var isDOMException = utils.isDOMException; var isError = utils.isError; var isObject = utils.isObject; var isPlainObject = utils.isPlainObject; 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 supportsFetch = utils.supportsFetch; var supportsReferrerPolicy = utils.supportsReferrerPolicy; var serializeKeysForMessage = utils.serializeKeysForMessage; var serializeException = utils.serializeException; var sanitize = utils.sanitize;
var wrapConsoleMethod = require('./console').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 payload function 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 = { // SENTRY_RELEASE can be injected by https://github.com/getsentry/sentry-webpack-plugin release: _window.SENTRY_RELEASE && _window.SENTRY_RELEASE.id, logger: 'javascript', ignoreErrors: [], ignoreUrls: [], whitelistUrls: [], includePaths: [], headers: null, collectWindowErrors: true, captureUnhandledRejections: true, maxMessageLength: 0, // By default, truncates URL values to 250 chars maxUrlLength: 250, stackTraceLimit: 50, autoBreadcrumbs: true, instrument: true, sampleRate: 1, sanitizeKeys: [] }; this._fetchDefaults = { method: 'POST', // Despite all stars in the sky saying that Edge supports old draft syntax, aka 'never', 'always', 'origin' and 'default // https://caniuse.com/#feat=referrer-policy // It doesn't. And it throw exception instead of ignoring this parameter... // REF: https://github.com/getsentry/raven-js/issues/1233 referrerPolicy: supportsReferrerPolicy() ? 'origin' : '' }; 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]; } }
/*
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.27.2',
debug: false,
TraceKit: TraceKit, // alias to TraceKit
/*
@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; },
/*
@return {Raven} */ install: function() { var self = this; if (self.isSetup() && !self._isRavenInstalled) { TraceKit.report.subscribe(function() { self._handleOnErrorStackInfo.apply(self, arguments); });
if (self._globalOptions.captureUnhandledRejections) { self._attachPromiseRejectionHandler(); }
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; },
/*
@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(); },
/*
@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 = {}; }
return this.wrap(options, func).apply(this, args); },
/*
@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; },
/**
this._detachPromiseRejectionHandler(); this._unpatchFunctionToString(); this._restoreBuiltIns(); this._restoreConsole();
Error.stackTraceLimit = this._originalErrorStackTraceLimit; this._isRavenInstalled = false;
return this; },
/**
unhandledrejection
event/**
/**
/**
if (isErrorEvent(ex) && ex.error) { // If it is an ErrorEvent with
error
property, extract it to get actual Error ex = ex.error; } else if (isDOMError(ex) || isDOMException(ex)) { // If it is a DOMError or DOMException (which are legacy APIs, but still supported in some browsers) // then we just extract the name and message, as they don't provide anything else // https://developer.mozilla.org/en-US/docs/Web/API/DOMError // https://developer.mozilla.org/en-US/docs/Web/API/DOMException var name = ex.name || (isDOMError(ex) ? 'DOMError' : 'DOMException'); var message = ex.message ? name + ': ' + ex.message : name;return this.captureMessage( message, objectMerge(options, { // neither DOMError or DOMException provide stack trace and we most likely wont get it this way as well // but it's barely any overhead so we may at least try stacktrace: true, trimHeadFrames: options.trimHeadFrames + 1 }) ); } else if (isError(ex)) { // we have a real Error object ex = ex; } else if (isPlainObject(ex)) { // If it is plain Object, serialize it manually and extract options // This will allow us to group events based on top-level keys // which is much better than creating new group when any key/value change options = this._getCaptureExceptionOptionsFromPlainObject(options, ex); ex = new Error(options.message); } else { // If none of previous checks were valid, then it means that // it's not a DOMError/DOMException // it's not a plain Object // it's not a valid ErrorEvent (one with an error property) // it's not an Error // So bail out and capture it as a simple message: return this.captureMessage( ex, objectMerge(options, { stacktrace: true, // if we fall back to captureMessage, default to attempting a new trace trimHeadFrames: options.trimHeadFrames + 1 }) ); }
// 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; } }
return this; },
_getCaptureExceptionOptionsFromPlainObject: function(currentOptions, ex) { var exKeys = Object.keys(ex).sort(); var options = objectMerge(currentOptions, { message: 'Non-Error exception captured with keys: ' + serializeKeysForMessage(exKeys), fingerprint: [md5(exKeys)], extra: currentOptions.extra || {} }); options.extra.serialized = serializeException(ex);
return options; },
/*
@return {Raven} */ captureMessage: function(msg, options) { // config() automagically converts ignoreErrors from a list to a RegExp so we need to test for an // early call; we'll error on the side of logging anything called before configuration since it's // probably something you should see: if ( !!this._globalOptions.ignoreErrors.test && this._globalOptions.ignoreErrors.test(msg) ) { return; }
options = options || {}; msg = msg + ''; // Make sure it's actually a string
var data = objectMerge( { message: msg }, options );
var ex; // Generate a "synthetic" stack trace from this point. // NOTE: If you are a Sentry user, and you are seeing this stack frame, it is NOT indicative // of a bug with Raven.js. Sentry generates synthetic traces either by configuration, // or if it catches a thrown object without a "stack" property. try { throw new Error(msg); } catch (ex1) { ex = ex1; }
// null exception name so
Error
isn't prefixed to msg ex.name = null; var stack = TraceKit.computeStackTrace(ex);// stack[0] is
throw new Error(msg)
call itself, we are interested in the frame that was just before that, stack[1] var initialCall = isArray(stack.stack) && stack.stack[1];// if stack[1] is
Raven.captureException
, it means that someone passed a string to it and we redirected that call // to be handled bycaptureMessage
, thusinitialCall
is the 3rd one, not 2nd // initialCall => captureException(string) => captureMessage(string) if (initialCall && initialCall.func === 'Raven.captureException') { initialCall = stack.stack[2]; }var fileurl = (initialCall && initialCall.url) || '';
if ( !!this._globalOptions.ignoreUrls.test && this._globalOptions.ignoreUrls.test(fileurl) ) { return; }
if ( !!this._globalOptions.whitelistUrls.test && !this._globalOptions.whitelistUrls.test(fileurl) ) { return; }
// Always attempt to get stacktrace if message is empty. // It's the only way to provide any helpful information to the user. if (this._globalOptions.stacktrace || options.stacktrace || data.message === '') { // fingerprint on msg, not stack trace (legacy behavior, could be revisited) data.fingerprint = data.fingerprint == null ? msg : data.fingerprint;
options = objectMerge( { trimHeadFrames: 0 }, options ); // Since we know this is a synthetic trace, the top frame (this function call) // MUST be from Raven.js, so mark it for trimming // We add to the trim counter so that callers can choose to trim extra frames, such // as utility functions. options.trimHeadFrames += 1;
var frames = this._prepareFrames(stack, options); data.stacktrace = { // Sentry expects frames oldest to newest frames: frames.reverse() }; }
// Make sure that fingerprint is always wrapped in an array if (data.fingerprint) { data.fingerprint = isArray(data.fingerprint) ? data.fingerprint : [data.fingerprint]; }
// Fire away! this._send(data);
return this; },
captureBreadcrumb: function(obj) { var crumb = objectMerge( { timestamp: now() / 1000 }, obj );
if (isFunction(this._globalOptions.breadcrumbCallback)) { var result = this._globalOptions.breadcrumbCallback(crumb);
if (isObject(result) && !isEmptyObject(result)) { crumb = result; } else if (result === false) { return this; } }
this._breadcrumbs.push(crumb); if (this._breadcrumbs.length > this._globalOptions.maxBreadcrumbs) { this._breadcrumbs.shift(); } return this; },
addPlugin: function(plugin /arg1, arg2, ... argN/) { var pluginArgs = [].slice.call(arguments, 1);
this._plugins.push([plugin, pluginArgs]); if (this._isRavenInstalled) { this._drainPlugins(); }
return this; },
/*
@return {Raven} */ setUserContext: function(user) { // Intentionally do not merge here since that's an unexpected behavior. this._globalContext.user = user;
return this; },
/*
@return {Raven} */ setExtraContext: function(extra) { this._mergeContext('extra', extra);
return this; },
/*
@return {Raven} */ setTagsContext: function(tags) { this._mergeContext('tags', tags);
return this; },
/*
@return {Raven} */ clearContext: function() { this._globalContext = {};
return this; },
/*
@return {object} copy of context */ getContext: function() { // lol javascript return JSON.parse(stringify(this._globalContext)); },
/*
@return {Raven} */ setEnvironment: function(environment) { this._globalOptions.environment = environment;
return this; },
/*
@return {Raven} */ setRelease: function(release) { this._globalOptions.release = release;
return this; },
/*
@return {Raven} */ setDataCallback: function(callback) { var original = this._globalOptions.dataCallback; this._globalOptions.dataCallback = keepOriginalCallback(original, callback); return this; },
/*
@return {Raven} */ setBreadcrumbCallback: function(callback) { var original = this._globalOptions.breadcrumbCallback; this._globalOptions.breadcrumbCallback = keepOriginalCallback(original, callback); return this; },
/*
@return {Raven} */ setShouldSendCallback: function(callback) { var original = this._globalOptions.shouldSendCallback; this._globalOptions.shouldSendCallback = keepOriginalCallback(original, callback); return this; },
/**
makeRequest
handler.return this; },
/*
@return {error} */ lastException: function() { return this._lastCapturedException; },
/*
@return {string} */ lastEventId: function() { return this._lastEventId; },
/*
@return {boolean} */ isSetup: function() { if (!this._hasJSON) return false; // needs JSON support if (!this._globalServer) { if (!this.ravenNotConfiguredError) { this.ravenNotConfiguredError = true; this._logDebug('error', 'Error: Raven has not been configured.'); } return false; } return true; },
afterLoad: function() { // TODO: remove window dependence?
// Attempt to initialize Raven on load var RavenConfig = _window.RavenConfig; if (RavenConfig) { this.config(RavenConfig.dsn, RavenConfig.config).install(); } },
showReportDialog: function(options) { if ( !_document // doesn't work without a document (React native) ) return;
options = objectMerge( [[getLinesNotShownLabel( truncatedAfter, '', '')]]`