Skip to content

Commit 2237e36

Browse files
committed
feat(loader): Sync loader with JS monorepo
1 parent 2b4e3bd commit 2237e36

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/sentry/templates/sentry/js-sdk-loader.js.tmpl

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
// content.p = promise rejection
3030
// content.f = function call the Sentry
3131
if (
32-
(content.e ||
33-
content.p ||
32+
('e' in content ||
33+
'p' in content ||
3434
(content.f && content.f.indexOf('capture') > -1) ||
3535
(content.f && content.f.indexOf('showReportDialog') > -1)) &&
3636
lazy
@@ -56,7 +56,7 @@
5656
// come out in the wrong order. Because of that we don't need async=1 as GA does.
5757
// it was probably(?) a legacy behavior that they left to not modify few years old snippet
5858
// https://www.html5rocks.com/en/tutorials/speed/script-loading/
59-
var _currentScriptTag = _document.getElementsByTagName(_script)[0];
59+
var _currentScriptTag = _document.scripts[0];
6060
var _newScriptTag = _document.createElement(_script);
6161
_newScriptTag.src = _sdkBundleUrl;
6262
_newScriptTag.crossOrigin = 'anonymous';
@@ -68,6 +68,9 @@
6868
_window[_onerror] = _oldOnerror;
6969
_window[_onunhandledrejection] = _oldOnunhandledrejection;
7070

71+
// Add loader as SDK source
72+
_window.SENTRY_SDK_SOURCE = 'loader';
73+
7174
var SDK = _window[_namespace];
7275

7376
var oldInit = SDK.init;
@@ -137,9 +140,9 @@
137140

138141
// And now capture all previously caught exceptions
139142
for (var i = 0; i < data.length; i++) {
140-
if (data[i].e && tracekitErrorHandler) {
143+
if ('e' in data[i] && tracekitErrorHandler) {
141144
tracekitErrorHandler.apply(_window, data[i].e);
142-
} else if (data[i].p && tracekitUnhandledRejectionHandler) {
145+
} else if ('p' in data[i] && tracekitUnhandledRejectionHandler) {
143146
tracekitUnhandledRejectionHandler.apply(_window, [data[i].p]);
144147
}
145148
}
@@ -198,9 +201,9 @@
198201

199202
// Do the same store/queue/call operations for `onunhandledrejection` event
200203
var _oldOnunhandledrejection = _window[_onunhandledrejection];
201-
_window[_onunhandledrejection] = function(exception) {
204+
_window[_onunhandledrejection] = function(e) {
202205
queue({
203-
p: exception.reason
206+
p: 'reason' in e ? e.reason : 'detail' in e && 'reason' in e.detail ? e.detail.reason : e
204207
});
205208
if (_oldOnunhandledrejection) _oldOnunhandledrejection.apply(_window, arguments);
206209
};

0 commit comments

Comments
 (0)