@@ -20,6 +20,7 @@ var _window = typeof window !== 'undefined' ? window
2020 : typeof self !== 'undefined' ? self
2121 : { } ;
2222var _document = _window . document ;
23+ var _navigator = _window . navigator ;
2324
2425// First, check for JSON support
2526// If there is no JSON, we no-op the core features of Raven
@@ -28,6 +29,7 @@ function Raven() {
2829 this . _hasJSON = ! ! ( typeof JSON === 'object' && JSON . stringify ) ;
2930 // Raven can run in contexts where there's no document (react-native)
3031 this . _hasDocument = ! isUndefined ( _document ) ;
32+ this . _hasNavigator = ! isUndefined ( _navigator ) ;
3133 this . _lastCapturedException = null ;
3234 this . _lastEventId = null ;
3335 this . _globalServer = null ;
@@ -1301,20 +1303,23 @@ Raven.prototype = {
13011303 } ,
13021304
13031305 _getHttpData : function ( ) {
1304- if ( ! this . _hasDocument || ! _document . location || ! _document . location . href ) {
1305- return ;
1306+ if ( ! this . _hasNavigator && ! this . _hasDocument ) return ;
1307+ var httpData = { } ;
1308+
1309+ if ( this . _hasNavigator && _navigator . userAgent ) {
1310+ httpData . headers = {
1311+ 'User-Agent' : navigator . userAgent
1312+ } ;
13061313 }
13071314
1308- var httpData = {
1309- headers : {
1310- 'User-Agent' : navigator . userAgent
1315+ if ( this . _hasDocument ) {
1316+ if ( _document . location && _document . location . href ) {
1317+ httpData . url = _document . location . href ;
1318+ }
1319+ if ( _document . referrer ) {
1320+ if ( ! httpData . headers ) httpData . headers = { } ;
1321+ httpData . headers . Referer = _document . referrer ;
13111322 }
1312- } ;
1313-
1314- httpData . url = _document . location . href ;
1315-
1316- if ( _document . referrer ) {
1317- httpData . headers . Referer = _document . referrer ;
13181323 }
13191324
13201325 return httpData ;
0 commit comments