@@ -64,7 +64,7 @@ function Raven() {
64
64
this . _breadcrumbs = [ ] ;
65
65
this . _breadcrumbLimit = 20 ;
66
66
this . _lastCapturedEvent = null ;
67
- this . _keypressTimeout = null ;
67
+ this . _keypressTimeout ;
68
68
this . _location = window . location ;
69
69
this . _lastHref = this . _location && this . _location . href ;
70
70
@@ -622,19 +622,16 @@ Raven.prototype = {
622
622
/**
623
623
* Wraps addEventListener to capture UI breadcrumbs
624
624
* @param evtName the event name (e.g. "click")
625
- * @param fn the function being wrapped
626
625
* @returns {Function }
627
626
* @private
628
627
*/
629
628
_breadcrumbEventHandler : function ( evtName ) {
630
629
var self = this ;
631
630
return function ( evt ) {
632
- // if there's a keypress event still queued up (debounce
633
- // hasn't flushed yet), flush it immediately before processing
634
- // this event
635
- if ( self . _keypressTimeout ) {
636
- self . _keypressCapture ( ) ;
637
- }
631
+ // reset keypress timeout; e.g. triggering a 'click' after
632
+ // a 'keypress' will reset the keypress debounce so that a new
633
+ // set of keypresses can be recorded
634
+ self . _keypressTimeout = null ;
638
635
639
636
// It's possible this handler might trigger multiple times for the same
640
637
// event (e.g. event propagation through node ancestors). Ignore if we've
@@ -662,25 +659,18 @@ Raven.prototype = {
662
659
} ;
663
660
} ,
664
661
665
- _keypressCapture : function ( evt ) {
666
- evt = evt || this . _lastKeypressEvent ;
667
- this . _lastKeypressEvent = null ;
668
-
669
- if ( this . _keypressTimeout ) {
670
- clearTimeout ( this . _keypressTimeout ) ;
671
- this . _keypressTimeout = null ;
672
- }
673
-
674
- return this . _breadcrumbEventHandler ( 'input' ) ( evt ) ;
675
- } ,
676
-
662
+ /**
663
+ * Wraps addEventListener to capture keypress UI events
664
+ * @returns {Function }
665
+ * @private
666
+ */
677
667
_keypressEventHandler : function ( ) {
678
- var self = this ;
679
- var debounceDuration = 1000 ; // milliseconds
668
+ var self = this ,
669
+ debounceDuration = 1000 ; // milliseconds
680
670
681
671
// TODO: if somehow user switches keypress target before
682
672
// debounce timeout is triggered, we will only capture
683
- // a single breadcrumb from the LAST target (acceptable?)
673
+ // a single breadcrumb from the FIRST target (acceptable?)
684
674
685
675
return function ( evt ) {
686
676
var target = evt . target ,
@@ -692,10 +682,15 @@ Raven.prototype = {
692
682
if ( ! tagName || tagName !== 'INPUT' && tagName !== 'TEXTAREA' )
693
683
return ;
694
684
695
- clearTimeout ( self . _keypressTimeout ) ;
696
- self . _lastKeypressEvent = evt ;
685
+ // record first keypress in a series, but ignore subsequent
686
+ // keypresses until debounce clears
687
+ var timeout = self . _keypressTimeout ;
688
+ if ( ! timeout ) {
689
+ self . _breadcrumbEventHandler ( 'input' ) ( evt ) ;
690
+ }
691
+ clearTimeout ( timeout ) ;
697
692
self . _keypressTimeout = setTimeout ( function ( ) {
698
- self . _keypressCapture ( evt ) ;
693
+ self . _keypressTimeout = null ;
699
694
} , debounceDuration ) ;
700
695
} ;
701
696
} ,
@@ -1201,10 +1196,6 @@ Raven.prototype = {
1201
1196
// Send along our own collected metadata with extra
1202
1197
data . extra [ 'session:duration' ] = now ( ) - this . _startTime ;
1203
1198
1204
- // flush debounced keypress breadcrumb capture (if there is one)
1205
- if ( this . _keypressTimeout ) {
1206
- this . _keypressCapture ( ) ;
1207
- }
1208
1199
if ( this . _breadcrumbs && this . _breadcrumbs . length > 0 ) {
1209
1200
// intentionally make shallow copy so that additions
1210
1201
// to breadcrumbs aren't accidentally sent in this request
0 commit comments