Skip to content

guard against document.location being null or undefined #357

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 25, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/raven.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions test/raven.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -185,7 +185,6 @@ describe('globals', function() {
assert.isUndefined(data.headers.Referer);
}
});

});

describe('isUndefined', function() {
Expand Down