import { Event as SentryEvent , Exception as SentryException , Stacktrace , } from "@sentry/browser" ; import { api } from "electron-util" ; /** Application base path used for URL normalization. */ const APP_PATH = api . app . getAppPath ( ) . replace ( /\\/g , "/" ) ; param url param base returns export const normalizeUrl = ( url , base = APP_PATH ) : string => { const escapedBase = base . replace ( /[|\\{}()[\]^$+*?.]/g , "\\$&" ) ; return decodeURI ( url ) . replace ( /\\/g , "/" ) . replace ( new RegExp ( `(file://)?/*${ escapedBase }/*` , "ig" ) , "app:///" ) ; } ; param event const getStacktrace = ( event ) : Stacktrace | undefined => { const { stacktrace , exception } = event ; if ( stacktrace ) { return stacktrace ; } if ( exception ) { if ( exception [ 0 ] ) { return exception [ 0 ] . stacktrace ; } const raven = ( exception as any ) as { values : SentryException [ ] ; } ; if ( raven . values && raven . values [ 0 ] ) { return raven . values [ 0 ] . stacktrace ; } } return undefined ; } ; /**
 * Normalizes all URLs in an event. See  normalizeUrl for more
 * information. Mutates the passed in event.
 *
 *  param event export const normalizeEvent = ( event ) : SentryEvent => { const copy = { ... event } ; const stacktrace = getStacktrace ( copy ) ; if ( stacktrace && stacktrace . frames ) { stacktrace . frames . forEach ( ( frame ) => { if ( frame . filename ) { frame . filename = normalizeUrl ( frame . filename ) ; } } ) ; } const breadcrumbs = copy . breadcrumbs ; if ( breadcrumbs ) { breadcrumbs . forEach ( ( crumb ) => { if ( crumb . category === "navigation" ) { crumb . data ! . from = normalizeUrl ( crumb . data ! . from ) ; crumb . data ! . to = normalizeUrl ( crumb . data ! . to ) ; } } ) ; } const { request = { } } = copy ; if ( request . url ) { request . url = normalizeUrl ( request . url ) ; } if ( request . headers ) { delete request . headers [ "User-Agent" ] ; } const { tags = { } } = copy ; delete tags . server_name ; return copy ; } ;