Skip to content

Commit 33dc820

Browse files
committed
fix: Let Edge to send fetch requests using default config
1 parent f4a2862 commit 33dc820

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/raven.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ var isSameStacktrace = utils.isSameStacktrace;
2727
var parseUrl = utils.parseUrl;
2828
var fill = utils.fill;
2929
var supportsFetch = utils.supportsFetch;
30+
var supportsReferrerPolicy = utils.supportsReferrerPolicy;
3031

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

@@ -90,7 +91,11 @@ function Raven() {
9091
this._fetchDefaults = {
9192
method: 'POST',
9293
keepalive: true,
93-
referrerPolicy: 'origin'
94+
// Despite all stars in the sky saying that Edge supports old draft syntax, aka 'never', 'always', 'origin' and 'default
95+
// https://caniuse.com/#feat=referrer-policy
96+
// It doesn't. And it throw exception instead of ignoring this parameter...
97+
// REF: https://github.com/getsentry/raven-js/issues/1233
98+
referrerPolicy: supportsReferrerPolicy() ? 'origin' : ''
9499
};
95100
this._ignoreOnError = 0;
96101
this._isRavenInstalled = false;

src/utils.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,24 @@ function supportsFetch() {
7979
}
8080
}
8181

82+
// Despite all stars in the sky saying that Edge supports old draft syntax, aka 'never', 'always', 'origin' and 'default
83+
// https://caniuse.com/#feat=referrer-policy
84+
// It doesn't. And it throw exception instead of ignoring this parameter...
85+
// REF: https://github.com/getsentry/raven-js/issues/1233
86+
function supportsReferrerPolicy() {
87+
if (!supportsFetch()) return false;
88+
89+
try {
90+
// eslint-disable-next-line no-new
91+
new Request('pickleRick', {
92+
referrerPolicy: 'origin'
93+
});
94+
return true;
95+
} catch (e) {
96+
return false;
97+
}
98+
}
99+
82100
function wrappedCallback(callback) {
83101
function dataCallback(data, original) {
84102
var normalizedData = callback(data) || data;
@@ -431,6 +449,7 @@ module.exports = {
431449
isEmptyObject: isEmptyObject,
432450
supportsErrorEvent: supportsErrorEvent,
433451
supportsFetch: supportsFetch,
452+
supportsReferrerPolicy: supportsReferrerPolicy,
434453
wrappedCallback: wrappedCallback,
435454
each: each,
436455
objectMerge: objectMerge,

0 commit comments

Comments
 (0)