Skip to content

Commit 7d9c06a

Browse files
committed
Wrap XMLHttp.prototype.send instead of open (fixes #453)
1 parent 1068a0c commit 7d9c06a

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/raven.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -615,10 +615,10 @@ Raven.prototype = {
615615
}
616616
});
617617

618-
var origOpen;
618+
var origSend;
619619
if ('XMLHttpRequest' in window) {
620-
origOpen = XMLHttpRequest.prototype.open;
621-
fill(XMLHttpRequest.prototype, 'open', function(origOpen) {
620+
origSend = XMLHttpRequest.prototype.send;
621+
fill(XMLHttpRequest.prototype, 'send', function(origOpen) {
622622
return function (data) { // preserve arity
623623
var xhr = this;
624624
'onreadystatechange onload onerror onprogress'.replace(/\w+/g, function (prop) {
@@ -628,7 +628,7 @@ Raven.prototype = {
628628
}, true /* noUndo */); // don't track filled methods on XHR instances
629629
}
630630
});
631-
origOpen.apply(this, arguments);
631+
origSend.apply(this, arguments);
632632
};
633633
});
634634
}

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)