diff --git a/src/raven.js b/src/raven.js index fb9d2a15499a..e2192e354e47 100644 --- a/src/raven.js +++ b/src/raven.js @@ -679,13 +679,18 @@ function now() { } function getHttpData() { + if (!document.location || !document.location.href) { + return; + } + var http = { - url: document.location.href, headers: { 'User-Agent': navigator.userAgent } }; + http.url = document.location.href; + if (document.referrer) { http.headers.Referer = document.referrer; } @@ -696,13 +701,18 @@ function getHttpData() { function send(data) { if (!isSetup()) return; - data = objectMerge({ + var baseData = { project: globalProject, logger: globalOptions.logger, platform: 'javascript', // sentry.interfaces.Http - request: getHttpData() - }, data); + }; + var http = getHttpData(); + if (http) { + baseData.http = http; + } + + data = objectMerge(baseData, data); // Merge in the tags and extra separately since objectMerge doesn't handle a deep merge data.tags = objectMerge(objectMerge({}, globalOptions.tags), data.tags); diff --git a/test/raven.test.js b/test/raven.test.js index e26a36ef1743..99bc8d59ba32 100644 --- a/test/raven.test.js +++ b/test/raven.test.js @@ -170,7 +170,7 @@ describe('globals', function() { var data = getHttpData(); it('should have a url', function() { - assert.equal(data.url, window.location.href); + assert.equal(data.url, window.location.href); }); it('should have the user-agent header', function() { @@ -185,7 +185,6 @@ describe('globals', function() { assert.isUndefined(data.headers.Referer); } }); - }); describe('isUndefined', function() {