'use strict';
import * as platform from 'platform';
/** Report errors to Sentry
* @module sentryErrorReporting
*/
import {host} from '../../../utility/host';
import {domains} from '../../../utility/domains';
/** Initialize Sentry
*/
export default function sentryErrorReporting() {
const COMMIT_HASH = process.env.COMMIT_HASH; // eslint-disable-line no-process-env
if (host.isProduction || host.isStaging || host.isTesting) {
// Load the secondary script to do the actual work (integrate it later possibly)
const scriptNode = document.createElement('script');
scriptNode.src = 'https://js.sentry-cdn.com/1d69a1d7420d4e7cb41674e7627f156f.min.js';
scriptNode.setAttribute('crossorigin', 'anonymous');
host.siteJSLoadingElement.parentNode.insertBefore( scriptNode, host.siteJSLoadingElement );
scriptNode.addEventListener('load', () => {
const location = host.locationDomain;
const isAuthorizedDomain = !host.isProduction || domains.isOurDomain(location);
/* eslint-disable no-undef */
if (!isAuthorizedDomain) {
Sentry.captureMessage(`Site JS is running on unauthorized domain: ${location}`, 'info');
}
Sentry.onLoad(() => { // eslint-disable-line no-undef
const supportedBrowsers = {
'Chrome': 80,
'Chrome Mobile': 80,
'Microsoft Edge': 80,
'Firefox': 70,
'Firefox Mobile': 70,
'IE': 11,
'Opera': 66,
// Note: the Opera iOS version is considerably lower, but considering the low market share, I think it's fine
'Opera Mobile': 60,
'Safari': 11,
'Samsung Internet': 7,
'UC Browser': 10
};
Sentry.setTag('outdatedBrowser', (supportedBrowsers[platform.name] &&
parseInt(platform.version.split('.')[0], 10) < supportedBrowsers[platform.name]));
Sentry.setTag('detectedBrowserName', platform.name);
Sentry.setTag('detectedBrowserVersion', platform.version.split('.')[0]);
const options = { // eslint-disable-line no-undef
environment: host.environment,
ignoreErrors: [
/'?\$'? is not defined/,
/'?j(q|Q)uery'? is not defined/,
/Can't find variable: \$/,
/Can't find variable: jQuery/
],
release: 'phm-goldenfrog-web@' + COMMIT_HASH, // eslint-disable-line camelcase
};
if (!isAuthorizedDomain) {
options.beforeSend = (event) => {
// We only want the "unauthorized domain" message to go through
return event.level === 'info' ? event : null;
};
}
Sentry.init(options);
/* eslint-enable */
});
});
} else {
DEBUG && console.log("Commit Hash: " + COMMIT_HASH); /* FE-2856 */// eslint-disable-line
}
}