@@ -742,21 +742,36 @@ Raven.prototype = {
742742 fill ( xhrproto , 'send' , function ( origSend ) {
743743 return function ( data ) { // preserve arity
744744 var xhr = this ;
745- 'onreadystatechange onload onerror onprogress' . replace ( / \w + / g, function ( prop ) {
745+
746+ function onreadystatechangeHandler ( ) {
747+ if ( xhr . __raven_xhr && ( xhr . readyState === 1 || xhr . readyState === 4 ) ) {
748+ try {
749+ // touching statusCode in some platforms throws
750+ // an exception
751+ xhr . __raven_xhr . status_code = xhr . status ;
752+ } catch ( e ) { /* do nothing */ }
753+ self . captureBreadcrumb ( 'http_request' , xhr . __raven_xhr ) ;
754+ }
755+ }
756+
757+ 'onload onerror onprogress' . replace ( / \w + / g, function ( prop ) {
746758 if ( prop in xhr && isFunction ( xhr [ prop ] ) ) {
747759 fill ( xhr , prop , function ( orig ) {
748- if ( prop === 'onreadystatechange' && xhr . __raven_xhr && ( xhr . readyState === 1 || xhr . readyState === 4 ) ) {
749- try {
750- // touching statusCode in some platforms throws
751- // an exception
752- xhr . __raven_xhr . status_code = xhr . status ;
753- } catch ( e ) { /* do nothing */ }
754- self . captureBreadcrumb ( 'http_request' , xhr . __raven_xhr ) ;
755- }
756760 return self . wrap ( orig ) ;
757761 } , true /* noUndo */ ) ; // don't track filled methods on XHR instances
758762 }
759763 } ) ;
764+
765+ if ( 'onreadystatechange' in xhr && isFunction ( xhr . onreadystatechange ) ) {
766+ fill ( xhr , 'onreadystatechange' , function ( orig ) {
767+ return self . wrap ( orig , undefined , onreadystatechangeHandler ) ;
768+ } , true /* noUndo */ ) ;
769+ } else {
770+ // if onreadystatechange wasn't actually set by the page on this xhr, we
771+ // are free to set our own and capture the breadcrumb
772+ xhr . onreadystatechange = onreadystatechangeHandler ;
773+ }
774+
760775 return origSend . apply ( this , arguments ) ;
761776 } ;
762777 } ) ;
0 commit comments