File tree Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -813,8 +813,15 @@ Raven.prototype = {
813813 // Capture breadcrubms from any click that is unhandled / bubbled up all the way
814814 // to the document. Do this before we instrument addEventListener.
815815 if ( this . _hasDocument ) {
816- document . addEventListener ( 'click' , self . _breadcrumbEventHandler ( 'click' ) ) ;
817- document . addEventListener ( 'keypress' , self . _keypressEventHandler ( ) ) ;
816+ if ( document . addEventListener ) {
817+ document . addEventListener ( 'click' , self . _breadcrumbEventHandler ( 'click' ) ) ;
818+ document . addEventListener ( 'keypress' , self . _keypressEventHandler ( ) ) ;
819+ }
820+ else {
821+ // IE8 Compatibility
822+ document . attachEvent ( 'onclick' , self . _breadcrumbEventHandler ( 'click' ) ) ;
823+ document . attachEvent ( 'onkeypress' , self . _keypressEventHandler ( ) ) ;
824+ }
818825 }
819826
820827 // event targets borrowed from bugsnag-js:
Original file line number Diff line number Diff line change @@ -2130,6 +2130,23 @@ describe('install/uninstall', function () {
21302130 Raven . install ( ) ;
21312131 assert . isTrue ( TraceKit . report . subscribe . calledOnce ) ;
21322132 } ) ;
2133+
2134+ it ( 'should use attachEvent instead of addEventListener in IE8' , function ( ) {
2135+ // Maintain a ref to the old function so we can restore it later.
2136+ var temp = document . addEventListener ;
2137+
2138+ // Test setup.
2139+ this . sinon . stub ( Raven , 'isSetup' ) . returns ( true ) ;
2140+ document . addEventListener = false ;
2141+ document . attachEvent = this . sinon . stub ( ) ;
2142+
2143+ // Invoke and assert.
2144+ Raven . install ( ) ;
2145+ assert . isTrue ( document . attachEvent . called ) ;
2146+
2147+ // Cleanup.
2148+ document . addEventListener = temp ;
2149+ } ) ;
21332150 } ) ;
21342151
21352152 describe ( '.uninstall' , function ( ) {
You can’t perform that action at this time.
0 commit comments