Skip to content

Commit 3880e00

Browse files
committed
Don't capture breadcrumbs for Sentry XHRs
1 parent a2b8ef3 commit 3880e00

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-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+
// intentionally checking against 0 here (start of string)
782+
if (url.indexOf(self._globalEndpoint) !== 0) {
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: 29 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,35 @@ 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+
debugger;
377+
iframeExecute(iframe, done,
378+
function () {
379+
// some browsers trigger onpopstate for load / reset breadcrumb state
380+
Raven._breadcrumbs = [];
381+
382+
var xhr = new XMLHttpRequest();
383+
xhr.open('GET', 'https://example.com/api/1/store/');
384+
xhr.setRequestHeader('Content-type', 'application/json');
385+
xhr.onreadystatechange = function () {
386+
// don't fire `done` handler until at least *one* onreadystatechange
387+
// has occurred (doesn't actually need to finish)
388+
if (xhr.readyState === 4) {
389+
setTimeout(done);
390+
}
391+
};
392+
xhr.send();
393+
},
394+
function () {
395+
var Raven = iframe.contentWindow.Raven,
396+
breadcrumbs = Raven._breadcrumbs;
397+
398+
assert.equal(breadcrumbs.length, 0);
399+
}
400+
);
401+
});
402+
375403
it('should record a mouse click on element WITH click handler present', function (done) {
376404
var iframe = this.iframe;
377405

0 commit comments

Comments
 (0)