Object.defineProperty(exports, '__esModule', { value: true }); const utils = require('@sentry/utils'); const debugBuild = require('../debug-build.js'); const integration = require('../integration.js'); // "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. const DEFAULT_IGNORE_ERRORS = [ /^Script error\.?$/, /^Javascript error: Script error\.? on line 0$/, /^ResizeObserver loop completed with undelivered notifications.$/, // The browser logs this when a ResizeObserver handler takes a bit longer. Usually this is not an actual issue though. It indicates slowness. /^Cannot redefine property: googletag$/, // This is thrown when google tag manager is used in combination with an ad blocker "undefined is not an object (evaluating 'a.L')", // Random error that happens but not actionable or noticeable to end-users. 'can\'t redefine non-configurable property "solana"', // Probably a browser extension or custom browser (Brave) throwing this error "vv().getRestrictions is not a function. (In 'vv().getRestrictions(1,a)', 'vv().getRestrictions' is undefined)", // Error thrown by GTM, seemingly not affecting end-users "Can't find variable: _AutofillCallbackHandler", // Unactionable error in instagram webview https://developers.facebook.com/community/threads/320013549791141/ ]; /** Options for the InboundFilters integration */ const INTEGRATION_NAME = 'InboundFilters'; const _inboundFiltersIntegration = ((options = {}) => { return { name: INTEGRATION_NAME, processEvent(event, _hint, client) { const clientOptions = client.getOptions(); const mergedOptions = _mergeOptions(options, clientOptions); return _shouldDropEvent(event, mergedOptions) ? null : event; }, }; }) ; const inboundFiltersIntegration = integration.defineIntegration(_inboundFiltersIntegration); function _mergeOptions( internalOptions = {}, clientOptions = {}, ) { return { allowUrls: [...(internalOptions.allowUrls || []), ...(clientOptions.allowUrls || [])], denyUrls: [...(internalOptions.denyUrls || []), ...(clientOptions.denyUrls || [])], ignoreErrors: [ ...(internalOptions.ignoreErrors || []), ...(clientOptions.ignoreErrors || []), ...(internalOptions.disableErrorDefaults ? [] : DEFAULT_IGNORE_ERRORS), ], ignoreTransactions: [...(internalOptions.ignoreTransactions || []), ...(clientOptions.ignoreTransactions || [])], ignoreInternal: internalOptions.ignoreInternal !== undefined ? internalOptions.ignoreInternal : true, }; } function _shouldDropEvent(event, options) { if (options.ignoreInternal && _isSentryError(event)) { debugBuild.DEBUG_BUILD && utils.logger.warn(`Event dropped due to being internal Sentry Error.\nEvent: ${utils.getEventDescription(event)}`); return true; } if (_isIgnoredError(event, options.ignoreErrors)) { debugBuild.DEBUG_BUILD && utils.logger.warn( `Event dropped due to being matched by \`ignoreErrors\` option.\nEvent: ${utils.getEventDescription(event)}`, ); return true; } if (_isUselessError(event)) { debugBuild.DEBUG_BUILD && utils.logger.warn( `Event dropped due to not having an error message, error type or stacktrace.\nEvent: ${utils.getEventDescription( event, )}`, ); return true; } if (_isIgnoredTransaction(event, options.ignoreTransactions)) { debugBuild.DEBUG_BUILD && utils.logger.warn( `Event dropped due to being matched by \`ignoreTransactions\` option.\nEvent: ${utils.getEventDescription(event)}`, ); return true; } if (_isDeniedUrl(event, options.denyUrls)) { debugBuild.DEBUG_BUILD && utils.logger.warn( `Event dropped due to being matched by \`denyUrls\` option.\nEvent: ${utils.getEventDescription( event, )}.\nUrl: ${_getEventFilterUrl(event)}`, ); return true; } if (!_isAllowedUrl(event, options.allowUrls)) { debugBuild.DEBUG_BUILD && utils.logger.warn( `Event dropped due to not being matched by \`allowUrls\` option.\nEvent: ${utils.getEventDescription( event, )}.\nUrl: ${_getEventFilterUrl(event)}`, ); return true; } return false; } function _isIgnoredError(event, ignoreErrors) { // If event.type, this is not an error if (event.type || !ignoreErrors || !ignoreErrors.length) { return false; } return _getPossibleEventMessages(event).some(message => utils.stringMatchesSomePattern(message, ignoreErrors)); } function _isIgnoredTransaction(event, ignoreTransactions) { if (event.type !== 'transaction' || !ignoreTransactions || !ignoreTransactions.length) { return false; } const name = event.transaction; return name ? utils.stringMatchesSomePattern(name, ignoreTransactions) : false; } function _isDeniedUrl(event, denyUrls) { // TODO: Use Glob instead? if (!denyUrls || !denyUrls.length) { return false; } const url = _getEventFilterUrl(event); return !url ? false : utils.stringMatchesSomePattern(url, denyUrls); } function _isAllowedUrl(event, allowUrls) { // TODO: Use Glob instead? if (!allowUrls || !allowUrls.length) { return true; } const url = _getEventFilterUrl(event); return !url ? true : utils.stringMatchesSomePattern(url, allowUrls); } function _getPossibleEventMessages(event) { const possibleMessages = []; if (event.message) { possibleMessages.push(event.message); } let lastException; try { // @ts-expect-error Try catching to save bundle size lastException = event.exception.values[event.exception.values.length - 1]; } catch (e) { // try catching to save bundle size checking existence of variables } if (lastException) { if (lastException.value) { possibleMessages.push(lastException.value); if (lastException.type) { possibleMessages.push(`${lastException.type}: ${lastException.value}`); } } } return possibleMessages; } function _isSentryError(event) { try { // @ts-expect-error can't be a sentry error if undefined return event.exception.values[0].type === 'SentryError'; } catch (e) { // ignore } return false; } function _getLastValidUrl(frames = []) { for (let i = frames.length - 1; i >= 0; i--) { const frame = frames[i]; if (frame && frame.filename !== '' && frame.filename !== '[native code]') { return frame.filename || null; } } return null; } function _getEventFilterUrl(event) { try { let frames; try { // @ts-expect-error we only care about frames if the whole thing here is defined frames = event.exception.values[0].stacktrace.frames; } catch (e) { // ignore } return frames ? _getLastValidUrl(frames) : null; } catch (oO) { debugBuild.DEBUG_BUILD && utils.logger.error(`Cannot extract url for event ${utils.getEventDescription(event)}`); return null; } } function _isUselessError(event) { if (event.type) { // event is not an error return false; } // We only want to consider events for dropping that actually have recorded exception values. if (!event.exception || !event.exception.values || event.exception.values.length === 0) { return false; } return ( // No top-level message !event.message && // There are no exception values that have a stacktrace, a non-generic-Error type or value !event.exception.values.some(value => value.stacktrace || (value.type && value.type !== 'Error') || value.value) ); } exports.inboundFiltersIntegration = inboundFiltersIntegration; //# sourceMappingURL=inboundfilters.js.map