Shoora
9/25/2019 - 11:33 PM

injectScript.js

injectScript('https://cdn.ravenjs.com/3.22.3/console/raven.min.js', function (err) {
  if (err) {
    console.warn('Could not load Raven.js script:', err);
    return;
  }
  if (!('Raven' in window)) {
    console.warn('Could not find `window.Raven` global');
    return;
  }
  ravenLoaded();
});

function ravenLoaded () {
  console.log('Raven.js script loaded');
  Raven.config('https://e359be9fb9324addb0dc97b664cf5ee6@sentry.io/294878')
       .install();
  offlineStoragePlugin(Raven);
}

function injectScript (src, callback) {
  var script = document.createElement('script');
  script.src = src;
  script.crossorigin = 'anonymous';
  script.addEventListener('load', function () {
    if (callback) {
      callback(null, true);
    }
  });
  script.addEventListener('error', function (err) {
    if (callback) {
      callback(err);
    }
  });
  document.head.appendChild(script);
  return script;
}