Skip to content

Add crossOrigin option #362

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/raven.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var _Raven = window.Raven,
ignoreUrls: [],
whitelistUrls: [],
includePaths: [],
crossOrigin: 'anonymous',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add this also into the flushRavenState() in raven.test.js plz.

collectWindowErrors: true,
tags: {},
maxMessageLength: 100,
Expand Down Expand Up @@ -759,7 +760,10 @@ function makeRequest(data) {
var img = newImage(),
src = globalServer + authQueryString + '&sentry_data=' + encodeURIComponent(JSON.stringify(data));

img.crossOrigin = 'anonymous';
if (globalOptions.crossOrigin || globalOptions.crossOrigin === '') {
img.crossOrigin = globalOptions.crossOrigin;
}

img.onload = function success() {
triggerEvent('success', {
data: data,
Expand Down
36 changes: 34 additions & 2 deletions test/raven.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1081,16 +1081,48 @@ describe('globals', function() {
});

describe('makeRequest', function() {
var imageCache;

beforeEach(function () {
imageCache = [];
this.sinon.stub(window, 'newImage', function(){ var img = {}; imageCache.push(img); return img; });
})

it('should load an Image', function() {
authQueryString = '?lol';
globalServer = 'http://localhost/';
var imageCache = [];
this.sinon.stub(window, 'newImage', function(){ var img = {}; imageCache.push(img); return img; });

makeRequest({foo: 'bar'});
assert.equal(imageCache.length, 1);
assert.equal(imageCache[0].src, 'http://localhost/?lol&sentry_data=%7B%22foo%22%3A%22bar%22%7D');
});

it('should populate crossOrigin based on globalOptions', function() {
globalOptions = {
crossOrigin: 'something'
};
makeRequest({foo: 'bar'});
assert.equal(imageCache.length, 1);
assert.equal(imageCache[0].crossOrigin, 'something');
});

it('should populate crossOrigin if empty string', function() {
globalOptions = {
crossOrigin: ''
};
makeRequest({foo: 'bar'});
assert.equal(imageCache.length, 1);
assert.equal(imageCache[0].crossOrigin, '');
});

it('should not populate crossOrigin if falsey', function() {
globalOptions = {
crossOrigin: false
};
makeRequest({foo: 'bar'});
assert.equal(imageCache.length, 1);
assert.isUndefined(imageCache[0].crossOrigin);
});
});

describe('handleStackInfo', function() {
Expand Down