From f49bdd02a5c45779acbb7f97e50a2eaa6db85c12 Mon Sep 17 00:00:00 2001 From: Ben Vinegar Date: Wed, 6 Jan 2016 17:25:27 -0800 Subject: [PATCH] Wrap XMLHttp.prototype.send instead of open (fixes #453) --- src/raven.js | 4 ++-- test/integration/test.js | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/raven.js b/src/raven.js index 873e444cb14b..fa720cf15fa4 100644 --- a/src/raven.js +++ b/src/raven.js @@ -652,7 +652,7 @@ Raven.prototype = { }); if ('XMLHttpRequest' in window) { - fill(XMLHttpRequest.prototype, 'open', function(origOpen) { + fill(XMLHttpRequest.prototype, 'send', function(origSend) { return function (data) { // preserve arity var xhr = this; 'onreadystatechange onload onerror onprogress'.replace(/\w+/g, function (prop) { @@ -662,7 +662,7 @@ Raven.prototype = { }, true /* noUndo */); // don't track filled methods on XHR instances } }); - origOpen.apply(this, arguments); + origSend.apply(this, arguments); }; }); } diff --git a/test/integration/test.js b/test/integration/test.js index 1ca4b101e212..82bd0c5cb48c 100644 --- a/test/integration/test.js +++ b/test/integration/test.js @@ -244,12 +244,20 @@ describe('integration', function () { iframeExecute(iframe, done, function () { - setTimeout(done); var xhr = new XMLHttpRequest(); + + // intentionally assign event handlers *after* XMLHttpRequest.prototype.open, + // since this is what jQuery does + // https://github.com/jquery/jquery/blob/master/src/ajax/xhr.js#L37 + + xhr.open('GET', 'example.json') xhr.onreadystatechange = function () { + setTimeout(done); + // replace onreadystatechange with no-op so exception doesn't + // fire more than once as XHR changes loading state + xhr.onreadystatechange = function () {}; foo(); }; - xhr.open('GET', 'example.json'); xhr.send(); }, function () {