Last active
November 8, 2018 13:38
-
-
Save simonkberg/bca699125b9a55d93288a67c34169c4a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(win, doc, version, onError, onUnhandledRejection, sentry) { | |
var SENTRY_SDK = win.SENTRY_SDK; | |
var queue = function(exception) { | |
queue.data.push(exception); | |
}; | |
queue.data = []; | |
win[sentry] = function() { | |
var SDK = win.Sentry; | |
var args = [].slice.call(arguments); | |
var method = args.shift(); | |
if (method) { | |
if (SDK) { | |
SDK[method].apply(SDK, args); | |
} else { | |
queue.data.push({ m: method, a: args }); | |
} | |
} | |
}; | |
var oldOnError = win[onError]; | |
win[onError] = function(message, source, lineno, colno, exception) { | |
queue({ e: [].slice.call(arguments) }); | |
if (oldOnError) { | |
oldOnError.apply(win, arguments); | |
} | |
}; | |
var oldOnUnhandledRejection = win[onUnhandledRejection]; | |
win[onUnhandledRejection] = function(exception) { | |
queue({ p: exception.reason }); | |
if (oldOnUnhandledRejection) { | |
oldOnUnhandledRejection.apply(win, arguments); | |
} | |
}; | |
var currentScriptTag = doc.getElementsByTagName("script")[0]; | |
var newScriptTag = doc.createElement("script"); | |
newScriptTag.src = | |
"https://browser.sentry-cdn.com/" + version + "/bundle.min.js"; | |
newScriptTag.crossorigin = "anonymous"; | |
newScriptTag.addEventListener("load", function() { | |
try { | |
win[onError] = oldOnError; | |
win[onUnhandledRejection] = oldOnUnhandledRejection; | |
var data = queue.data; | |
var SDK = win.Sentry; | |
SDK.init(SENTRY_SDK); | |
var tracekitErrorHandler = win[onError]; | |
if (data.length) { | |
for (var i = 0; i < data.length; i++) { | |
if (data[i].e) { | |
tracekitErrorHandler.apply(SDK.TraceKit, data[i].e); | |
} else if (data[i].p) { | |
SDK.captureException(data[i].p); | |
} else if (data[i].m) { | |
SDK[data[i].m].apply(SDK, data[i].a); | |
} | |
} | |
data.length = 0; | |
} | |
} catch (o_O) { | |
console.error(o_O); | |
} | |
}); | |
currentScriptTag.parentNode.insertBefore(newScriptTag, currentScriptTag); | |
})(window, document, "4.3.0", "onerror", "onunhandledrejection", "sentry"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!function(n,e,t,a,r,o){var c=n.SENTRY_SDK,i=function(n){i.data.push(n)};i.data=[],n[o]=function(){var e=n.Sentry,t=[].slice.call(arguments),a=t.shift();a&&(e?e[a].apply(e,t):i.data.push({m:a,a:t}))};var p=n[a];n[a]=function(e,t,a,r,o){i({e:[].slice.call(arguments)}),p&&p.apply(n,arguments)};var s=n[r];n[r]=function(e){i({p:e.reason}),s&&s.apply(n,arguments)};var l=e.getElementsByTagName("script")[0],d=e.createElement("script");d.src="https://browser.sentry-cdn.com/"+t+"/bundle.min.js",d.crossorigin="anonymous",d.addEventListener("load",function(){try{n[a]=p,n[r]=s;var e=i.data,t=n.Sentry;t.init(c);var o=n[a];if(e.length){for(var l=0;l<e.length;l++)e[l].e?o.apply(t.TraceKit,e[l].e):e[l].p?t.captureException(e[l].p):e[l].m&&t[e[l].m].apply(t,e[l].a);e.length=0}}catch(n){console.error(n)}}),l.parentNode.insertBefore(d,l)}(window,document,"4.3.0","onerror","onunhandledrejection","sentry"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment