Skip to content

Commit d9bb595

Browse files
authored
fix: Revert that bundle will be appended to body (#1943)
1 parent ec9f3f3 commit d9bb595

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

packages/browser/src/loader.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
// come out in the wrong order. Because of that we don't need async=1 as GA does.
5959
// it was probably(?) a legacy behavior that they left to not modify few years old snippet
6060
// https://www.html5rocks.com/en/tutorials/speed/script-loading/
61+
var _currentScriptTag = _document.getElementsByTagName(_script)[0];
6162
var _newScriptTag = _document.createElement(_script);
6263
_newScriptTag.src = _sdkBundleUrl;
6364
_newScriptTag.crossorigin = 'anonymous';
@@ -90,9 +91,7 @@
9091
}
9192
});
9293

93-
// We append the script to the body because if you use an `onload` callback it could happen that
94-
// the `onLoad` of the already injected SDK will be called, which breaks the setup flow.
95-
document.body.appendChild(_newScriptTag);
94+
_currentScriptTag.parentNode.insertBefore(_newScriptTag, _currentScriptTag);
9695
}
9796

9897
function sdkLoaded(callbacks, SDK) {
@@ -107,8 +106,9 @@
107106
}
108107

109108
var initAlreadyCalled = false;
109+
var __sentry = _window['__SENTRY__'];
110110
// If there is a global __SENTRY__ that means that in any of the callbacks init() was already invoked
111-
if (!(typeof _window['__SENTRY__'] === 'undefined')) {
111+
if (!(typeof __sentry === 'undefined') && __sentry.hub && __sentry.hub.getClient()) {
112112
initAlreadyCalled = true;
113113
}
114114

0 commit comments

Comments
 (0)