MCPcopy Index your code
hub / github.com/getsentry/sentry-javascript / injectSdk

Function injectSdk

packages/browser/test/loader.js:52–101  ·  view source on GitHub ↗
(callbacks)

Source from the content-addressed store, hash-verified

50 queue.data = [];
51
52 function injectSdk(callbacks) {
53 if (injected) {
54 return;
55 }
56 injected = true;
57
58 // Create a `script` tag with provided SDK `url` and attach it just before the first, already existing `script` tag
59 // Scripts that are dynamically created and added to the document are async by default,
60 // they don't block rendering and execute as soon as they download, meaning they could
61 // come out in the wrong order. Because of that we don't need async=1 as GA does.
62 // it was probably(?) a legacy behavior that they left to not modify few years old snippet
63 // https://www.html5rocks.com/en/tutorials/speed/script-loading/
64 var _currentScriptTag = _document.scripts[0];
65 var _newScriptTag = _document.createElement(_script);
66 _newScriptTag.src = _sdkBundleUrl;
67 _newScriptTag.crossOrigin = 'anonymous';
68
69 // Once our SDK is loaded
70 _newScriptTag.addEventListener('load', function() {
71 try {
72 // Restore onerror/onunhandledrejection handlers
73 _window[_onerror] = _oldOnerror;
74 _window[_onunhandledrejection] = _oldOnunhandledrejection;
75
76 // Add loader as SDK source
77 _window.SENTRY_SDK_SOURCE = 'loader';
78
79 var SDK = _window[_namespace];
80
81 var oldInit = SDK.init;
82
83 // Configure it using provided DSN and config object
84 SDK.init = function(options) {
85 var target = _config;
86 for (var key in options) {
87 if (Object.prototype.hasOwnProperty.call(options, key)) {
88 target[key] = options[key];
89 }
90 }
91 oldInit(target);
92 };
93
94 sdkLoaded(callbacks, SDK);
95 } catch (o_O) {
96 console.error(o_O);
97 }
98 });
99
100 _currentScriptTag.parentNode.insertBefore(_newScriptTag, _currentScriptTag);
101 }
102
103 function sdkLoaded(callbacks, SDK) {
104 try {

Callers 2

queueFunction · 0.85
loader.jsFile · 0.85

Calls 4

sdkLoadedFunction · 0.85
callMethod · 0.80
addEventListenerMethod · 0.65
errorMethod · 0.65

Tested by

no test coverage detected