Skip to content

Commit

Permalink
fix: Let Edge to send fetch requests using default config
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilogorek committed Feb 20, 2018
1 parent f4a2862 commit 33dc820
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
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

0 comments on commit 33dc820

Please sign in to comment.