import { captureException , getCurrentHub , withScope } from '@sentry/core' ; import { Event as SentryEvent , Mechanism , Scope , WrappedFunction } from '@sentry/types' ; import { addExceptionMechanism , addExceptionTypeValue , htmlTreeAsString , normalize } from '@sentry/utils' ; const debounceDuration = 1000 ; let keypressTimeout ; let lastCapturedEvent ; let ignoreOnError = 0 ; hidden export function shouldIgnoreOnError ( ) { return ignoreOnError > 0 ; } hidden export function ignoreNextOnError ( ) { ignoreOnError += 1 ; setTimeout ( ( ) => { ignoreOnError -= 1 ; } ) ; } param fn returns hidden export function wrap ( fn , options = { } , before ? ) { if ( typeof fn !== 'function' ) { return fn ; } try { if ( fn . __sentry__ ) { return fn ; } if ( fn . __sentry_wrapped__ ) { return fn . __sentry_wrapped__ ; } } catch ( e ) { return fn ; } const sentryWrapped = function ( this ) : void { if ( before && typeof before === 'function' ) { before . apply ( this , arguments ) ; } const args = Array . prototype . slice . call ( arguments ) ; try { const wrappedArguments = args . map ( ( arg ) => wrap ( arg , options ) ) ; if ( fn . handleEvent ) { return fn . handleEvent . apply ( this , wrappedArguments ) ; } return fn . apply ( this , wrappedArguments ) ; } catch ( ex ) { ignoreNextOnError ( ) ; withScope ( ( scope ) => { scope . addEventProcessor ( ( event ) => { const processedEvent = { ... event } ; if ( options . mechanism ) { addExceptionTypeValue ( processedEvent , undefined , undefined ) ; addExceptionMechanism ( processedEvent , options . mechanism ) ; } processedEvent . extra = { ... processedEvent . extra , arguments : normalize ( args , 3 ) , } ; return processedEvent ; } ) ; captureException ( ex ) ; } ) ; throw ex ; } } ; try { for ( const property in fn ) { if ( Object . prototype . hasOwnProperty . call ( fn , property ) ) { sentryWrapped [ property ] = fn [ property ] ; } } } catch ( _oO ) { } fn . prototype = fn . prototype || { } ; sentryWrapped . prototype = fn . prototype ; Object . defineProperty ( fn , '__sentry_wrapped__' , { enumerable : false , value : sentryWrapped , } ) ; Object . defineProperties ( sentryWrapped , { __sentry__ : { enumerable : false , value : true , } , __sentry_original__ : { enumerable : false , value : fn , } , } ) ; try { const descriptor = Object . getOwnPropertyDescriptor ( sentryWrapped , 'name' ) as PropertyDescriptor ; if ( descriptor . configurable ) { Object . defineProperty ( sentryWrapped , 'name' , { get ( ) { return fn . name ; } , } ) ; } } catch ( _oO ) { } return sentryWrapped ; } let debounceTimer = 0 ; param eventName returns hidden export function breadcrumbEventHandler ( eventName , debounce = false ) { return ( event ) => { keypressTimeout = undefined ; if ( ! event || lastCapturedEvent === event ) { return ; } lastCapturedEvent = event ; const captureBreadcrumb = ( ) => { let target ; try { target = event . target ? htmlTreeAsString ( event . target as Node ) : htmlTreeAsString ( ( event as unknown ) as Node ) ; } catch ( e ) { target = '<unknown>' ; } if ( target . length === 0 ) { return ; } getCurrentHub ( ) . addBreadcrumb ( { category : `ui.${ eventName }` , message : target , } , { event , name : eventName , } ) ; } ; if ( debounceTimer ) { clearTimeout ( debounceTimer ) ; } if ( debounce ) { debounceTimer = setTimeout ( captureBreadcrumb ) ; } else { captureBreadcrumb ( ) ; } } ; } returns hidden export function keypressEventHandler ( ) { return ( event ) => { let target ; try { target = event . target ; } catch ( e ) { return ; } const tagName = target && ( target as HTMLElement ) . tagName ; if ( ! tagName || ( tagName !== 'INPUT' && tagName !== 'TEXTAREA' && ! ( target as HTMLElement ) . isContentEditable ) ) { return ; } if ( ! keypressTimeout ) { breadcrumbEventHandler ( 'input' ) ( event ) ; } clearTimeout ( keypressTimeout ) ; keypressTimeout = ( setTimeout ( ( ) => { keypressTimeout = undefined ; } , debounceDuration ) as any ) as number ; } ; }