Skip to content
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
7 changes: 6 additions & 1 deletion src/raven.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var isSameStacktrace = utils.isSameStacktrace;
var parseUrl = utils.parseUrl;
var fill = utils.fill;
var supportsFetch = utils.supportsFetch;
var supportsReferrerPolicy = utils.supportsReferrerPolicy;

var wrapConsoleMethod = require('./console').wrapMethod;

Expand Down Expand Up @@ -90,7 +91,11 @@ function Raven() {
this._fetchDefaults = {
method: 'POST',
keepalive: true,
referrerPolicy: 'origin'
// Despite all stars in the sky saying that Edge supports old draft syntax, aka 'never', 'always', 'origin' and 'default
// https://caniuse.com/#feat=referrer-policy
// It doesn't. And it throw exception instead of ignoring this parameter...
// REF: https://github.com/getsentry/raven-js/issues/1233
referrerPolicy: supportsReferrerPolicy() ? 'origin' : ''
};
this._ignoreOnError = 0;
this._isRavenInstalled = false;
Expand Down
19 changes: 19 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,24 @@ function supportsFetch() {
}
}

// Despite all stars in the sky saying that Edge supports old draft syntax, aka 'never', 'always', 'origin' and 'default
// https://caniuse.com/#feat=referrer-policy
// It doesn't. And it throw exception instead of ignoring this parameter...
// REF: https://github.com/getsentry/raven-js/issues/1233
function supportsReferrerPolicy() {
if (!supportsFetch()) return false;

try {
// eslint-disable-next-line no-new
new Request('pickleRick', {
referrerPolicy: 'origin'
});
return true;
} catch (e) {
return false;
}
}

function wrappedCallback(callback) {
function dataCallback(data, original) {
var normalizedData = callback(data) || data;
Expand Down Expand Up @@ -431,6 +449,7 @@ module.exports = {
isEmptyObject: isEmptyObject,
supportsErrorEvent: supportsErrorEvent,
supportsFetch: supportsFetch,
supportsReferrerPolicy: supportsReferrerPolicy,
wrappedCallback: wrappedCallback,
each: each,
objectMerge: objectMerge,
Expand Down
3 changes: 2 additions & 1 deletion test/raven.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var utils = require('../src/utils');
var joinRegExp = utils.joinRegExp;
var supportsErrorEvent = utils.supportsErrorEvent;
var supportsFetch = utils.supportsFetch;
var supportsReferrerPolicy = utils.supportsReferrerPolicy;

// window.console must be stubbed in for browsers that don't have it
if (typeof window.console === 'undefined') {
Expand Down Expand Up @@ -1784,7 +1785,7 @@ describe('globals', function() {
'http://localhost/?a=1&b=2',
{
keepalive: true,
referrerPolicy: 'origin',
referrerPolicy: supportsReferrerPolicy() ? 'origin' : '',
method: 'POST',
body: '{"foo":"bar"}'
}
Expand Down