File tree 2 files changed +26
-2
lines changed
2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -813,8 +813,15 @@ Raven.prototype = {
813
813
// Capture breadcrubms from any click that is unhandled / bubbled up all the way
814
814
// to the document. Do this before we instrument addEventListener.
815
815
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
+ }
818
825
}
819
826
820
827
// event targets borrowed from bugsnag-js:
Original file line number Diff line number Diff line change @@ -2130,6 +2130,23 @@ describe('install/uninstall', function () {
2130
2130
Raven . install ( ) ;
2131
2131
assert . isTrue ( TraceKit . report . subscribe . calledOnce ) ;
2132
2132
} ) ;
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
+ } ) ;
2133
2150
} ) ;
2134
2151
2135
2152
describe ( '.uninstall' , function ( ) {
You can’t perform that action at this time.
0 commit comments