diff --git a/packages/browser/src/exports.ts b/packages/browser/src/exports.ts index e9e947de8559..93677f34fa82 100644 --- a/packages/browser/src/exports.ts +++ b/packages/browser/src/exports.ts @@ -111,4 +111,4 @@ export { linkedErrorsIntegration } from './integrations/linkederrors'; export { browserApiErrorsIntegration } from './integrations/trycatch'; // eslint-disable-next-line deprecation/deprecation -export { GlobalHandlers, TryCatch, Breadcrumbs, LinkedErrors, HttpContext, Dedupe } from './integrations'; +export { TryCatch, Breadcrumbs, LinkedErrors, HttpContext, Dedupe } from './integrations'; diff --git a/packages/browser/src/integrations/globalhandlers.ts b/packages/browser/src/integrations/globalhandlers.ts index c1096e7c2132..e2aa0b6116f0 100644 --- a/packages/browser/src/integrations/globalhandlers.ts +++ b/packages/browser/src/integrations/globalhandlers.ts @@ -1,19 +1,9 @@ -/* eslint-disable @typescript-eslint/no-unsafe-member-access */ -import { captureEvent, convertIntegrationFnToClass, defineIntegration, getClient } from '@sentry/core'; -import type { - Client, - Event, - Integration, - IntegrationClass, - IntegrationFn, - Primitive, - StackParser, -} from '@sentry/types'; +import { captureEvent, defineIntegration, getClient } from '@sentry/core'; +import type { Client, Event, IntegrationFn, Primitive, StackParser } from '@sentry/types'; import { addGlobalErrorInstrumentationHandler, addGlobalUnhandledRejectionInstrumentationHandler, getLocationHref, - isErrorEvent, isPrimitive, isString, logger, @@ -57,18 +47,6 @@ const _globalHandlersIntegration = ((options: Partial void }> & { - new (options?: Partial): Integration; -}; - function _installGlobalOnErrorHandler(client: Client): void { addGlobalErrorInstrumentationHandler(data => { const { stackParser, attachStacktrace } = getOptions(); @@ -79,15 +57,12 @@ function _installGlobalOnErrorHandler(client: Client): void { const { msg, url, line, column, error } = data; - const event = - error === undefined && isString(msg) - ? _eventFromIncompleteOnError(msg, url, line, column) - : _enhanceEventWithInitialFrame( - eventFromUnknownInput(stackParser, error || msg, undefined, attachStacktrace, false), - url, - line, - column, - ); + const event = _enhanceEventWithInitialFrame( + eventFromUnknownInput(stackParser, error || msg, undefined, attachStacktrace, false), + url, + line, + column, + ); event.level = 'error'; @@ -132,24 +107,23 @@ function _getUnhandledRejectionError(error: unknown): unknown { return error; } - // eslint-disable-next-line @typescript-eslint/no-explicit-any - const e = error as any; - // dig the object of the rejection out of known event types try { + type ErrorWithReason = { reason: unknown }; // PromiseRejectionEvents store the object of the rejection under 'reason' // see https://developer.mozilla.org/en-US/docs/Web/API/PromiseRejectionEvent - if ('reason' in e) { - return e.reason; + if ('reason' in (error as ErrorWithReason)) { + return (error as ErrorWithReason).reason; } + type CustomEventWithDetail = { detail: { reason: unknown } }; // something, somewhere, (likely a browser extension) effectively casts PromiseRejectionEvents // to CustomEvents, moving the `promise` and `reason` attributes of the PRE into // the CustomEvent's `detail` attribute, since they're not part of CustomEvent's spec // see https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent and // https://github.com/getsentry/sentry-javascript/issues/2380 - else if ('detail' in e && 'reason' in e.detail) { - return e.detail.reason; + if ('detail' in (error as CustomEventWithDetail) && 'reason' in (error as CustomEventWithDetail).detail) { + return (error as CustomEventWithDetail).detail.reason; } } catch {} // eslint-disable-line no-empty @@ -176,38 +150,6 @@ function _eventFromRejectionWithPrimitive(reason: Primitive): Event { }; } -/** - * This function creates a stack from an old, error-less onerror handler. - */ -// eslint-disable-next-line @typescript-eslint/no-explicit-any -function _eventFromIncompleteOnError(msg: any, url: any, line: any, column: any): Event { - const ERROR_TYPES_RE = - /^(?:[Uu]ncaught (?:exception: )?)?(?:((?:Eval|Internal|Range|Reference|Syntax|Type|URI|)Error): )?(.*)$/i; - - // If 'message' is ErrorEvent, get real message from inside - let message = isErrorEvent(msg) ? msg.message : msg; - let name = 'Error'; - - const groups = message.match(ERROR_TYPES_RE); - if (groups) { - name = groups[1]; - message = groups[2]; - } - - const event = { - exception: { - values: [ - { - type: name, - value: message, - }, - ], - }, - }; - - return _enhanceEventWithInitialFrame(event, url, line, column); -} - // eslint-disable-next-line @typescript-eslint/no-explicit-any function _enhanceEventWithInitialFrame(event: Event, url: any, line: any, column: any): Event { // event.exception diff --git a/packages/browser/src/integrations/index.ts b/packages/browser/src/integrations/index.ts index 17ac85b31232..977cdabba8a4 100644 --- a/packages/browser/src/integrations/index.ts +++ b/packages/browser/src/integrations/index.ts @@ -1,5 +1,4 @@ /* eslint-disable deprecation/deprecation */ -export { GlobalHandlers } from './globalhandlers'; export { TryCatch } from './trycatch'; export { Breadcrumbs } from './breadcrumbs'; export { LinkedErrors } from './linkederrors';