Skip to content

Commit 9a374f4

Browse files
committed
Merge pull request #557 from getsentry/no-sentry-xhrs
Don't capture breadcrumbs for Sentry XHRs
2 parents a2b8ef3 + 5920f12 commit 9a374f4

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed

src/raven.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -777,11 +777,16 @@ Raven.prototype = {
777777
var xhrproto = XMLHttpRequest.prototype;
778778
fill(xhrproto, 'open', function(origOpen) {
779779
return function (method, url) { // preserve arity
780-
this.__raven_xhr = {
781-
method: method,
782-
url: url,
783-
status_code: null
784-
};
780+
781+
// if Sentry key appears in URL, don't capture
782+
if (url.indexOf(self._globalKey) === -1) {
783+
this.__raven_xhr = {
784+
method: method,
785+
url: url,
786+
status_code: null
787+
};
788+
}
789+
785790
return origOpen.apply(this, arguments);
786791
};
787792
});

test/integration/test.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,6 @@ describe('integration', function () {
306306

307307
iframeExecute(iframe, done,
308308
function () {
309-
310309
// some browsers trigger onpopstate for load / reset breadcrumb state
311310
Raven._breadcrumbs = [];
312311

@@ -372,6 +371,34 @@ describe('integration', function () {
372371
);
373372
});
374373

374+
it('should NOT capture breadcrumbs from XMLHttpRequests to the Sentry store endpoint', function (done) {
375+
var iframe = this.iframe;
376+
iframeExecute(iframe, done,
377+
function () {
378+
// some browsers trigger onpopstate for load / reset breadcrumb state
379+
Raven._breadcrumbs = [];
380+
381+
var xhr = new XMLHttpRequest();
382+
xhr.open('GET', 'https://example.com/api/1/store/?sentry_key=public');
383+
xhr.setRequestHeader('Content-type', 'application/json');
384+
xhr.onreadystatechange = function () {
385+
// don't fire `done` handler until at least *one* onreadystatechange
386+
// has occurred (doesn't actually need to finish)
387+
if (xhr.readyState === 4) {
388+
setTimeout(done);
389+
}
390+
};
391+
xhr.send();
392+
},
393+
function () {
394+
var Raven = iframe.contentWindow.Raven,
395+
breadcrumbs = Raven._breadcrumbs;
396+
397+
assert.equal(breadcrumbs.length, 0);
398+
}
399+
);
400+
});
401+
375402
it('should record a mouse click on element WITH click handler present', function (done) {
376403
var iframe = this.iframe;
377404

0 commit comments

Comments
 (0)