1
- import { captureException , getCurrentHub , withScope } from '@sentry/core' ;
1
+ import { captureException , withScope } from '@sentry/core' ;
2
2
import { Event as SentryEvent , Mechanism , Scope , WrappedFunction } from '@sentry/types' ;
3
- import { addExceptionMechanism , addExceptionTypeValue , htmlTreeAsString , normalize } from '@sentry/utils' ;
3
+ import { addExceptionMechanism , addExceptionTypeValue , normalize } from '@sentry/utils' ;
4
4
5
- const debounceDuration : number = 1000 ;
6
- let keypressTimeout : number | undefined ;
7
- let lastCapturedEvent : Event | undefined ;
8
5
let ignoreOnError : number = 0 ;
9
6
10
7
/**
@@ -37,7 +34,6 @@ export function wrap(
37
34
fn : WrappedFunction ,
38
35
options : {
39
36
mechanism ?: Mechanism ;
40
- capture ?: boolean ;
41
37
} = { } ,
42
38
before ?: WrappedFunction ,
43
39
) : any {
@@ -64,15 +60,15 @@ export function wrap(
64
60
}
65
61
66
62
const sentryWrapped : WrappedFunction = function ( this : any ) : void {
67
- // tslint:disable-next-line:strict-type-predicates
68
- if ( before && typeof before === 'function' ) {
69
- before . apply ( this , arguments ) ;
70
- }
71
-
72
63
const args = Array . prototype . slice . call ( arguments ) ;
73
64
74
65
// tslint:disable:no-unsafe-any
75
66
try {
67
+ // tslint:disable-next-line:strict-type-predicates
68
+ if ( before && typeof before === 'function' ) {
69
+ before . apply ( this , arguments ) ;
70
+ }
71
+
76
72
const wrappedArguments = args . map ( ( arg : any ) => wrap ( arg , options ) ) ;
77
73
78
74
if ( fn . handleEvent ) {
@@ -82,7 +78,6 @@ export function wrap(
82
78
// is expected behavior and NOT indicative of a bug with sentry.javascript.
83
79
return fn . handleEvent . apply ( this , wrappedArguments ) ;
84
80
}
85
-
86
81
// Attempt to invoke user-land function
87
82
// NOTE: If you are a Sentry user, and you are seeing this stack frame, it
88
83
// means the sentry.javascript SDK caught an error invoking your application code. This
@@ -163,106 +158,3 @@ export function wrap(
163
158
164
159
return sentryWrapped ;
165
160
}
166
-
167
- let debounceTimer : number = 0 ;
168
-
169
- /**
170
- * Wraps addEventListener to capture UI breadcrumbs
171
- * @param eventName the event name (e.g. "click")
172
- * @returns wrapped breadcrumb events handler
173
- * @hidden
174
- */
175
- export function breadcrumbEventHandler ( eventName : string , debounce : boolean = false ) : ( event : Event ) => void {
176
- return ( event : Event ) => {
177
- // reset keypress timeout; e.g. triggering a 'click' after
178
- // a 'keypress' will reset the keypress debounce so that a new
179
- // set of keypresses can be recorded
180
- keypressTimeout = undefined ;
181
- // It's possible this handler might trigger multiple times for the same
182
- // event (e.g. event propagation through node ancestors). Ignore if we've
183
- // already captured the event.
184
- if ( ! event || lastCapturedEvent === event ) {
185
- return ;
186
- }
187
-
188
- lastCapturedEvent = event ;
189
-
190
- const captureBreadcrumb = ( ) => {
191
- let target ;
192
-
193
- // Accessing event.target can throw (see getsentry/raven-js#838, #768)
194
- try {
195
- target = event . target ? htmlTreeAsString ( event . target as Node ) : htmlTreeAsString ( ( event as unknown ) as Node ) ;
196
- } catch ( e ) {
197
- target = '<unknown>' ;
198
- }
199
-
200
- if ( target . length === 0 ) {
201
- return ;
202
- }
203
-
204
- getCurrentHub ( ) . addBreadcrumb (
205
- {
206
- category : `ui.${ eventName } ` , // e.g. ui.click, ui.input
207
- message : target ,
208
- } ,
209
- {
210
- event,
211
- name : eventName ,
212
- } ,
213
- ) ;
214
- } ;
215
-
216
- if ( debounceTimer ) {
217
- clearTimeout ( debounceTimer ) ;
218
- }
219
-
220
- if ( debounce ) {
221
- debounceTimer = setTimeout ( captureBreadcrumb ) ;
222
- } else {
223
- captureBreadcrumb ( ) ;
224
- }
225
- } ;
226
- }
227
-
228
- /**
229
- * Wraps addEventListener to capture keypress UI events
230
- * @returns wrapped keypress events handler
231
- * @hidden
232
- */
233
- export function keypressEventHandler ( ) : ( event : Event ) => void {
234
- // TODO: if somehow user switches keypress target before
235
- // debounce timeout is triggered, we will only capture
236
- // a single breadcrumb from the FIRST target (acceptable?)
237
- return ( event : Event ) => {
238
- let target ;
239
-
240
- try {
241
- target = event . target ;
242
- } catch ( e ) {
243
- // just accessing event properties can throw an exception in some rare circumstances
244
- // see: https://github.com/getsentry/raven-js/issues/838
245
- return ;
246
- }
247
-
248
- const tagName = target && ( target as HTMLElement ) . tagName ;
249
-
250
- // only consider keypress events on actual input elements
251
- // this will disregard keypresses targeting body (e.g. tabbing
252
- // through elements, hotkeys, etc)
253
- if ( ! tagName || ( tagName !== 'INPUT' && tagName !== 'TEXTAREA' && ! ( target as HTMLElement ) . isContentEditable ) ) {
254
- return ;
255
- }
256
-
257
- // record first keypress in a series, but ignore subsequent
258
- // keypresses until debounce clears
259
- if ( ! keypressTimeout ) {
260
- breadcrumbEventHandler ( 'input' ) ( event ) ;
261
- }
262
- clearTimeout ( keypressTimeout ) ;
263
-
264
- keypressTimeout = ( setTimeout ( ( ) => {
265
- keypressTimeout = undefined ;
266
- } , debounceDuration ) as any ) as number ;
267
- } ;
268
- }
0 commit comments