|
@@ -1,17 +1,27 @@
|
|
|
{% load sentry_helpers %}// Sentry Loader
|
|
|
-(function(_window, _document, _script, _onerror, _onunhandledrejection, _namespace, _publicKey, _sdkBundleUrl, _config) {
|
|
|
+(function(
|
|
|
+ _window,
|
|
|
+ _document,
|
|
|
+ _script,
|
|
|
+ _onerror,
|
|
|
+ _onunhandledrejection,
|
|
|
+ _namespace,
|
|
|
+ _publicKey,
|
|
|
+ _sdkBundleUrl,
|
|
|
+ _config
|
|
|
+) {
|
|
|
var lazy = true;
|
|
|
var forceLoad = false;
|
|
|
|
|
|
for (var i = 0; i < document.scripts.length; i++) {
|
|
|
if (document.scripts[i].src.indexOf(_publicKey) > -1) {
|
|
|
- lazy = !(document.scripts[i].dataset.lazy === 'no');
|
|
|
+ lazy = !(document.scripts[i].getAttribute('data-lazy') === 'no');
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
var injected = false;
|
|
|
- var onLoadCallback;
|
|
|
+ var onLoadCallbacks = [];
|
|
|
|
|
|
// Create a namespace and attach function that will store captured exception
|
|
|
// Because functions are also objects, we can attach the queue itself straight to it and save some bytes
|
|
@@ -20,7 +30,8 @@
|
|
|
// content.p = promise rejection
|
|
|
// content.f = function call the Sentry
|
|
|
if (
|
|
|
- (content.e || content.p ||
|
|
|
+ (content.e ||
|
|
|
+ content.p ||
|
|
|
(content.f && content.f.indexOf('capture') > -1) ||
|
|
|
(content.f && content.f.indexOf('showReportDialog') > -1)) &&
|
|
|
lazy
|
|
@@ -28,13 +39,13 @@
|
|
|
// We only want to lazy inject/load the sdk bundle if
|
|
|
// an error or promise rejection occured
|
|
|
// OR someone called `capture...` on the SDK
|
|
|
- injectSdk(onLoadCallback);
|
|
|
+ injectSdk(onLoadCallbacks);
|
|
|
}
|
|
|
queue.data.push(content);
|
|
|
};
|
|
|
queue.data = [];
|
|
|
|
|
|
- function injectSdk(callback) {
|
|
|
+ function injectSdk(callbacks) {
|
|
|
if (injected) {
|
|
|
return;
|
|
|
}
|
|
@@ -73,7 +84,7 @@
|
|
|
oldInit(target);
|
|
|
};
|
|
|
|
|
|
- sdkLoaded(callback, SDK);
|
|
|
+ sdkLoaded(callbacks, SDK);
|
|
|
} catch (o_O) {
|
|
|
console.error(o_O);
|
|
|
}
|
|
@@ -82,11 +93,14 @@
|
|
|
_currentScriptTag.parentNode.insertBefore(_newScriptTag, _currentScriptTag);
|
|
|
}
|
|
|
|
|
|
- function sdkLoaded(callback, SDK) {
|
|
|
+ function sdkLoaded(callbacks, SDK) {
|
|
|
try {
|
|
|
- if (callback) {
|
|
|
- callback();
|
|
|
+ for (var i = 0; i < callbacks.length; i++) {
|
|
|
+ if (typeof callbacks[i] === 'function') {
|
|
|
+ callbacks[i]();
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
var data = queue.data;
|
|
|
|
|
|
// We want to replay all calls to Sentry first to make sure init is called before
|
|
@@ -130,21 +144,21 @@
|
|
|
// We don't want to _window.Sentry = _window.Sentry || { ... } since we want to make sure
|
|
|
// that the first Sentry "instance" is our with onLoad
|
|
|
_window[_namespace] = {
|
|
|
- onLoad: function(callback) {
|
|
|
+ onLoad: function (callback) {
|
|
|
+ onLoadCallbacks.push(callback);
|
|
|
if (lazy && !forceLoad) {
|
|
|
- onLoadCallback = callback;
|
|
|
- } else {
|
|
|
- injectSdk(callback);
|
|
|
+ return;
|
|
|
}
|
|
|
+ injectSdk(onLoadCallbacks);
|
|
|
},
|
|
|
forceLoad: function() {
|
|
|
forceLoad = true;
|
|
|
if (lazy) {
|
|
|
setTimeout(function() {
|
|
|
- injectSdk(onLoadCallback);
|
|
|
+ injectSdk(onLoadCallbacks);
|
|
|
});
|
|
|
}
|
|
|
- },
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
[
|
|
@@ -155,10 +169,10 @@
|
|
|
'captureEvent',
|
|
|
'configureScope',
|
|
|
'withScope',
|
|
|
- 'showReportDialog',
|
|
|
+ 'showReportDialog'
|
|
|
].forEach(function(f) {
|
|
|
_window[_namespace][f] = function() {
|
|
|
- queue({f: f, a: arguments});
|
|
|
+ queue({ f: f, a: arguments });
|
|
|
};
|
|
|
});
|
|
|
|
|
@@ -168,7 +182,7 @@
|
|
|
_window[_onerror] = function(message, source, lineno, colno, exception) {
|
|
|
// Use keys as "data type" to save some characters"
|
|
|
queue({
|
|
|
- e: [].slice.call(arguments),
|
|
|
+ e: [].slice.call(arguments)
|
|
|
});
|
|
|
|
|
|
if (_oldOnerror) _oldOnerror.apply(_window, arguments);
|
|
@@ -178,14 +192,14 @@
|
|
|
var _oldOnunhandledrejection = _window[_onunhandledrejection];
|
|
|
_window[_onunhandledrejection] = function(exception) {
|
|
|
queue({
|
|
|
- p: exception.reason,
|
|
|
+ p: exception.reason
|
|
|
});
|
|
|
if (_oldOnunhandledrejection) _oldOnunhandledrejection.apply(_window, arguments);
|
|
|
};
|
|
|
|
|
|
if (!lazy) {
|
|
|
setTimeout(function() {
|
|
|
- injectSdk(onLoadCallback);
|
|
|
+ injectSdk(onLoadCallbacks);
|
|
|
});
|
|
|
}
|
|
|
})(window, document, "script", "onerror", "onunhandledrejection", "Sentry", "{{ publicKey|safe }}", "{{ jsSdkUrl|safe }}", {{ config|to_json|safe }});
|