Skip to content

Commit

Permalink
Send cookies.
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Wood committed Feb 17, 2016
1 parent 732add6 commit e4579ff
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
20 changes: 19 additions & 1 deletion honeybadger.js
Expand Up @@ -98,6 +98,23 @@
return data;
}

function cookies() {
var cookies = {},
pairs,
pair,
i;

pairs = document.cookie.split(/;\s*/);
for (i = 0; i < pairs.length; i++) {
pair = pairs[i].split('=', 2);
if (pair[0] && pair[1]) {
cookies[pair[0]] = pair[1];
}
}

return cookies;
}

function stackTrace(err) {
// From TraceKit: Opera 10 *destroys* its stacktrace property if you try to
// access the stack property first.
Expand Down Expand Up @@ -284,7 +301,8 @@
component: err.component || config('component'),
action: err.action || config('action'),
context: merge(self.context, err.context),
cgi_data: cgiData()
cgi_data: cgiData(),
cookies: cookies()
},
server: {
project_root: config('project_root') || (window.location.protocol + '//' + window.location.host),
Expand Down
22 changes: 21 additions & 1 deletion spec/honeybadger.spec.js
Expand Up @@ -314,6 +314,26 @@ describe('Honeybadger', function() {
});
});

describe('payload', function() {
beforeEach(function() {
Honeybadger.configure({
api_key: 'asdf'
});
});

it('includes cookies', function() {
document.cookie = 'foo=bar'
document.cookie = 'bar=baz'
Honeybadger.notify('testing');
afterNotify(function() {
expect(requests.length).toEqual(1);
expect(requests[0].url).toMatch('notice%5Brequest%5D%5Bcookies%5D%5Bfoo%5D=bar&notice%5Brequest%5D%5Bcookies%5D%5Bbar%5D=baz');
document.cookie = 'foo=bar;max-age=0'
document.cookie = 'bar=baz;max-age=0'
});
});
});

describe('payload query string', function() {
beforeEach(function() {
Honeybadger.configure({
Expand All @@ -322,7 +342,7 @@ describe('Honeybadger', function() {
});

it('serializes an object to a query string', function() {
Honeybadger.notify("testing", {
Honeybadger.notify('testing', {
context: {
foo: 'foo',
bar: {
Expand Down

0 comments on commit e4579ff

Please sign in to comment.