Skip to content

Sync loader between Sentry <-> monorepo #6990

Description

@AbhiPrasad

JS monorepo loader -> Sentry loader

### Tasks
- [ ] https://github.com/getsentry/sentry/pull/43880
- [ ] https://github.com/getsentry/sentry-javascript/pull/7001
- [ ] https://github.com/getsentry/getsentry/pull/9483
diff --git a/packages/browser/src/loader.js b/packages/browser/src/loader.js
index a914137f6..e1e413971 100644
--- a/packages/browser/src/loader.js+++ b/packages/browser/src/loader.js@@ -1,6 +1,4 @@-// prettier-ignore-// Prettier disabled due to trailing comma not working in IE10/11-(function(+{% load sentry_helpers %}(function(
_window,
_document,
_script,
@@ -31,8 +29,8 @@
// content.p = promise rejection
// content.f = function call the Sentry
if (
- ('e' in content ||- 'p' in content ||+ (content.e ||+ content.p ||
(content.f && content.f.indexOf('capture') > -1) ||
(content.f && content.f.indexOf('showReportDialog') > -1)) &&
lazy
@@ -58,10 +56,10 @@
// come out in the wrong order. Because of that we don't need async=1 as GA does.
// it was probably(?) a legacy behavior that they left to not modify few years old snippet
// https://www.html5rocks.com/en/tutorials/speed/script-loading/
- var _currentScriptTag = _document.scripts[0];+ var _currentScriptTag = _document.getElementsByTagName(_script)[0];
var _newScriptTag = _document.createElement(_script);
_newScriptTag.src = _sdkBundleUrl;
- _newScriptTag.setAttribute('crossorigin', 'anonymous');+ _newScriptTag.crossOrigin = 'anonymous';
// Once our SDK is loaded
_newScriptTag.addEventListener('load', function() {
@@ -70,9 +68,6 @@
_window[_onerror] = _oldOnerror;
_window[_onunhandledrejection] = _oldOnunhandledrejection;
- // Add loader as SDK source- _window.SENTRY_SDK_SOURCE = 'loader';-
var SDK = _window[_namespace];
var oldInit = SDK.init;
@@ -142,9 +137,9 @@
// And now capture all previously caught exceptions
for (var i = 0; i < data.length; i++) {
- if ('e' in data[i] && tracekitErrorHandler) {+ if (data[i].e && tracekitErrorHandler) {
tracekitErrorHandler.apply(_window, data[i].e);
- } else if ('p' in data[i] && tracekitUnhandledRejectionHandler) {+ } else if (data[i].p && tracekitUnhandledRejectionHandler) {
tracekitUnhandledRejectionHandler.apply(_window, [data[i].p]);
}
}
@@ -203,9 +198,9 @@
// Do the same store/queue/call operations for `onunhandledrejection` event
var _oldOnunhandledrejection = _window[_onunhandledrejection];
- _window[_onunhandledrejection] = function(e) {+ _window[_onunhandledrejection] = function(exception) {
queue({
- p: 'reason' in e ? e.reason : 'detail' in e && 'reason' in e.detail ? e.detail.reason : e+ p: exception.reason
});
if (_oldOnunhandledrejection) _oldOnunhandledrejection.apply(_window, arguments);
};
@@ -215,6 +210,4 @@
injectSdk(onLoadCallbacks);
});
}
-})(window, document, 'script', 'onerror', 'onunhandledrejection', 'Sentry', 'loader.js', '../../build/bundles/bundle.js', {- dsn: 'https://public@example.com/1'-});+})(window, document, 'script', 'onerror', 'onunhandledrejection', 'Sentry', '{{ publicKey|safe }}', '{{ jsSdkUrl|safe }}', {{ config|to_json|safe }});

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions