Skip to content

Commit 54bd178

Browse files
committed
Merge pull request #362 from chrisirhc/feature/add-cross-origin
Add crossOrigin option
2 parents faf722e + 8d2a68b commit 54bd178

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

src/raven.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ var _Raven = window.Raven,
1717
ignoreUrls: [],
1818
whitelistUrls: [],
1919
includePaths: [],
20+
crossOrigin: 'anonymous',
2021
collectWindowErrors: true,
2122
tags: {},
2223
maxMessageLength: 100,
@@ -759,7 +760,10 @@ function makeRequest(data) {
759760
var img = newImage(),
760761
src = globalServer + authQueryString + '&sentry_data=' + encodeURIComponent(JSON.stringify(data));
761762

762-
img.crossOrigin = 'anonymous';
763+
if (globalOptions.crossOrigin || globalOptions.crossOrigin === '') {
764+
img.crossOrigin = globalOptions.crossOrigin;
765+
}
766+
763767
img.onload = function success() {
764768
triggerEvent('success', {
765769
data: data,

test/raven.test.js

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,16 +1081,48 @@ describe('globals', function() {
10811081
});
10821082

10831083
describe('makeRequest', function() {
1084+
var imageCache;
1085+
1086+
beforeEach(function () {
1087+
imageCache = [];
1088+
this.sinon.stub(window, 'newImage', function(){ var img = {}; imageCache.push(img); return img; });
1089+
})
1090+
10841091
it('should load an Image', function() {
10851092
authQueryString = '?lol';
10861093
globalServer = 'http://localhost/';
1087-
var imageCache = [];
1088-
this.sinon.stub(window, 'newImage', function(){ var img = {}; imageCache.push(img); return img; });
10891094

10901095
makeRequest({foo: 'bar'});
10911096
assert.equal(imageCache.length, 1);
10921097
assert.equal(imageCache[0].src, 'http://localhost/?lol&sentry_data=%7B%22foo%22%3A%22bar%22%7D');
10931098
});
1099+
1100+
it('should populate crossOrigin based on globalOptions', function() {
1101+
globalOptions = {
1102+
crossOrigin: 'something'
1103+
};
1104+
makeRequest({foo: 'bar'});
1105+
assert.equal(imageCache.length, 1);
1106+
assert.equal(imageCache[0].crossOrigin, 'something');
1107+
});
1108+
1109+
it('should populate crossOrigin if empty string', function() {
1110+
globalOptions = {
1111+
crossOrigin: ''
1112+
};
1113+
makeRequest({foo: 'bar'});
1114+
assert.equal(imageCache.length, 1);
1115+
assert.equal(imageCache[0].crossOrigin, '');
1116+
});
1117+
1118+
it('should not populate crossOrigin if falsey', function() {
1119+
globalOptions = {
1120+
crossOrigin: false
1121+
};
1122+
makeRequest({foo: 'bar'});
1123+
assert.equal(imageCache.length, 1);
1124+
assert.isUndefined(imageCache[0].crossOrigin);
1125+
});
10941126
});
10951127

10961128
describe('handleStackInfo', function() {

0 commit comments

Comments
 (0)