UNPKG

@sentry/browser

Version:
102 lines (99 loc) 2.72 kB
import { GLOBAL_OBJ, getOriginalFunction, markFunctionWrapped, addNonEnumerableProperty, withScope, addExceptionTypeValue, addExceptionMechanism, captureException, getLocationHref } from '@sentry/core/browser'; const WINDOW = GLOBAL_OBJ; let ignoreOnError = 0; function shouldIgnoreOnError() { return ignoreOnError > 0; } function ignoreNextOnError() { ignoreOnError++; setTimeout(() => { ignoreOnError--; }); } function wrap(fn, options = {}) { function isFunction(fn2) { return typeof fn2 === "function"; } if (!isFunction(fn)) { return fn; } try { const wrapper = fn.__sentry_wrapped__; if (wrapper) { if (typeof wrapper === "function") { return wrapper; } else { return fn; } } if (getOriginalFunction(fn)) { return fn; } } catch { return fn; } const sentryWrapped = function(...args) { GLOBAL_OBJ._sentryWrappedDepth = (GLOBAL_OBJ._sentryWrappedDepth || 0) + 1; try { const wrappedArguments = args.map((arg) => wrap(arg, options)); return fn.apply(this, wrappedArguments); } catch (ex) { ignoreNextOnError(); withScope((scope) => { scope.addEventProcessor((event) => { if (options.mechanism) { addExceptionTypeValue(event, void 0, void 0); addExceptionMechanism(event, options.mechanism); } event.extra = { ...event.extra, arguments: args }; return event; }); captureException(ex); }); throw ex; } finally { GLOBAL_OBJ._sentryWrappedDepth = (GLOBAL_OBJ._sentryWrappedDepth || 0) - 1; } }; try { for (const property in fn) { if (Object.prototype.hasOwnProperty.call(fn, property)) { sentryWrapped[property] = fn[property]; } } } catch { } markFunctionWrapped(sentryWrapped, fn); addNonEnumerableProperty(fn, "__sentry_wrapped__", sentryWrapped); try { const descriptor = Object.getOwnPropertyDescriptor(sentryWrapped, "name"); if (descriptor.configurable) { Object.defineProperty(sentryWrapped, "name", { get() { return fn.name; } }); } } catch { } return sentryWrapped; } function getHttpRequestData() { const url = getLocationHref(); const { referrer } = WINDOW.document || {}; const { userAgent } = WINDOW.navigator || {}; const headers = { ...referrer && { Referer: referrer }, ...userAgent && { "User-Agent": userAgent } }; const request = { url, headers }; return request; } export { WINDOW, getHttpRequestData, ignoreNextOnError, shouldIgnoreOnError, wrap }; //# sourceMappingURL=helpers.js.map