| 101 | } |
| 102 | |
| 103 | function sdkLoaded(callbacks, SDK) { |
| 104 | try { |
| 105 | var data = queue.data; |
| 106 | |
| 107 | // We have to make sure to call all callbacks first |
| 108 | for (var i = 0; i < callbacks.length; i++) { |
| 109 | if (typeof callbacks[i] === 'function') { |
| 110 | callbacks[i](); |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | var initAlreadyCalled = false; |
| 115 | var __sentry = _window['__SENTRY__']; |
| 116 | // If there is a global __SENTRY__ that means that in any of the callbacks init() was already invoked |
| 117 | if (!(typeof __sentry === 'undefined') && __sentry.hub?.getClient()) { |
| 118 | initAlreadyCalled = true; |
| 119 | } |
| 120 | |
| 121 | // We want to replay all calls to Sentry and also make sure that `init` is called if it wasn't already |
| 122 | // We replay all calls to `Sentry.*` now |
| 123 | var calledSentry = false; |
| 124 | for (var i = 0; i < data.length; i++) { |
| 125 | if (data[i].f) { |
| 126 | calledSentry = true; |
| 127 | var call = data[i]; |
| 128 | if (initAlreadyCalled === false && call.f !== 'init') { |
| 129 | // First call always has to be init, this is a convenience for the user so call to init is optional |
| 130 | SDK.init(); |
| 131 | } |
| 132 | initAlreadyCalled = true; |
| 133 | SDK[call.f].apply(SDK, call.a); |
| 134 | } |
| 135 | } |
| 136 | if (initAlreadyCalled === false && calledSentry === false) { |
| 137 | // Sentry has never been called but we need Sentry.init() so call it |
| 138 | SDK.init(); |
| 139 | } |
| 140 | |
| 141 | // Because we installed the SDK, at this point we have an access to TraceKit's handler, |
| 142 | // which can take care of browser differences (eg. missing exception argument in onerror) |
| 143 | var tracekitErrorHandler = _window[_onerror]; |
| 144 | var tracekitUnhandledRejectionHandler = _window[_onunhandledrejection]; |
| 145 | |
| 146 | // And now capture all previously caught exceptions |
| 147 | for (var i = 0; i < data.length; i++) { |
| 148 | if ('e' in data[i] && tracekitErrorHandler) { |
| 149 | tracekitErrorHandler.apply(_window, data[i].e); |
| 150 | } else if ('p' in data[i] && tracekitUnhandledRejectionHandler) { |
| 151 | tracekitUnhandledRejectionHandler.apply(_window, [data[i].p]); |
| 152 | } |
| 153 | } |
| 154 | } catch (o_O) { |
| 155 | console.error(o_O); |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | // We make sure we do not overwrite window.Sentry since there could be already integrations in there |
| 160 | _window[_namespace] = _window[_namespace] || {}; |