Skip to content

Commit 6315478

Browse files
committed
Merge pull request #454 from getsentry/GH-453
Wrap XMLHttp.prototype.send instead of open (fixes #453)
2 parents c9ffb91 + f49bdd0 commit 6315478

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/raven.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ Raven.prototype = {
652652
});
653653

654654
if ('XMLHttpRequest' in window) {
655-
fill(XMLHttpRequest.prototype, 'open', function(origOpen) {
655+
fill(XMLHttpRequest.prototype, 'send', function(origSend) {
656656
return function (data) { // preserve arity
657657
var xhr = this;
658658
'onreadystatechange onload onerror onprogress'.replace(/\w+/g, function (prop) {
@@ -662,7 +662,7 @@ Raven.prototype = {
662662
}, true /* noUndo */); // don't track filled methods on XHR instances
663663
}
664664
});
665-
origOpen.apply(this, arguments);
665+
origSend.apply(this, arguments);
666666
};
667667
});
668668
}

test/integration/test.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,12 +244,20 @@ describe('integration', function () {
244244

245245
iframeExecute(iframe, done,
246246
function () {
247-
setTimeout(done);
248247
var xhr = new XMLHttpRequest();
248+
249+
// intentionally assign event handlers *after* XMLHttpRequest.prototype.open,
250+
// since this is what jQuery does
251+
// https://github.com/jquery/jquery/blob/master/src/ajax/xhr.js#L37
252+
253+
xhr.open('GET', 'example.json')
249254
xhr.onreadystatechange = function () {
255+
setTimeout(done);
256+
// replace onreadystatechange with no-op so exception doesn't
257+
// fire more than once as XHR changes loading state
258+
xhr.onreadystatechange = function () {};
250259
foo();
251260
};
252-
xhr.open('GET', 'example.json');
253261
xhr.send();
254262
},
255263
function () {

0 commit comments

Comments
 (0)