Skip to content

Commit 465f492

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

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

src/raven.js

+6-1
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

+19
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,

test/raven.test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ var utils = require('../src/utils');
2424
var joinRegExp = utils.joinRegExp;
2525
var supportsErrorEvent = utils.supportsErrorEvent;
2626
var supportsFetch = utils.supportsFetch;
27+
var supportsReferrerPolicy = utils.supportsReferrerPolicy;
2728

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

0 commit comments

Comments
 (0)