1 | import { Integrations, getIntegrationsToSetup, initAndBind, getReportDialogEndpoint, getCurrentHub } from '@sentry/core';
|
2 | import { stackParserFromStackParserOptions, supportsFetch, logger, resolvedSyncPromise, addInstrumentationHandler } from '@sentry/utils';
|
3 | import { BrowserClient } from './client.js';
|
4 | import { WINDOW, wrap as wrap$1 } from './helpers.js';
|
5 | import { GlobalHandlers } from './integrations/globalhandlers.js';
|
6 | import { TryCatch } from './integrations/trycatch.js';
|
7 | import { Breadcrumbs } from './integrations/breadcrumbs.js';
|
8 | import { LinkedErrors } from './integrations/linkederrors.js';
|
9 | import { HttpContext } from './integrations/httpcontext.js';
|
10 | import { Dedupe } from './integrations/dedupe.js';
|
11 | import { defaultStackParser } from './stack-parsers.js';
|
12 | import { makeFetchTransport } from './transports/fetch.js';
|
13 | import { makeXHRTransport } from './transports/xhr.js';
|
14 |
|
15 | const defaultIntegrations = [
|
16 | new Integrations.InboundFilters(),
|
17 | new Integrations.FunctionToString(),
|
18 | new TryCatch(),
|
19 | new Breadcrumbs(),
|
20 | new GlobalHandlers(),
|
21 | new LinkedErrors(),
|
22 | new Dedupe(),
|
23 | new HttpContext(),
|
24 | ];
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 | function init(options = {}) {
|
88 | if (options.defaultIntegrations === undefined) {
|
89 | options.defaultIntegrations = defaultIntegrations;
|
90 | }
|
91 | if (options.release === undefined) {
|
92 |
|
93 | if (typeof __SENTRY_RELEASE__ === 'string') {
|
94 | options.release = __SENTRY_RELEASE__;
|
95 | }
|
96 |
|
97 |
|
98 | if (WINDOW.SENTRY_RELEASE && WINDOW.SENTRY_RELEASE.id) {
|
99 | options.release = WINDOW.SENTRY_RELEASE.id;
|
100 | }
|
101 | }
|
102 | if (options.autoSessionTracking === undefined) {
|
103 | options.autoSessionTracking = true;
|
104 | }
|
105 | if (options.sendClientReports === undefined) {
|
106 | options.sendClientReports = true;
|
107 | }
|
108 |
|
109 | const clientOptions = {
|
110 | ...options,
|
111 | stackParser: stackParserFromStackParserOptions(options.stackParser || defaultStackParser),
|
112 | integrations: getIntegrationsToSetup(options),
|
113 | transport: options.transport || (supportsFetch() ? makeFetchTransport : makeXHRTransport),
|
114 | };
|
115 |
|
116 | initAndBind(BrowserClient, clientOptions);
|
117 |
|
118 | if (options.autoSessionTracking) {
|
119 | startSessionTracking();
|
120 | }
|
121 | }
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 | function showReportDialog(options = {}, hub = getCurrentHub()) {
|
129 |
|
130 | if (!WINDOW.document) {
|
131 | (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.error('Global document not defined in showReportDialog call');
|
132 | return;
|
133 | }
|
134 |
|
135 | const { client, scope } = hub.getStackTop();
|
136 | const dsn = options.dsn || (client && client.getDsn());
|
137 | if (!dsn) {
|
138 | (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.error('DSN not configured for showReportDialog call');
|
139 | return;
|
140 | }
|
141 |
|
142 | if (scope) {
|
143 | options.user = {
|
144 | ...scope.getUser(),
|
145 | ...options.user,
|
146 | };
|
147 | }
|
148 |
|
149 | if (!options.eventId) {
|
150 | options.eventId = hub.lastEventId();
|
151 | }
|
152 |
|
153 | const script = WINDOW.document.createElement('script');
|
154 | script.async = true;
|
155 | script.src = getReportDialogEndpoint(dsn, options);
|
156 |
|
157 | if (options.onLoad) {
|
158 | script.onload = options.onLoad;
|
159 | }
|
160 |
|
161 | const injectionPoint = WINDOW.document.head || WINDOW.document.body;
|
162 | if (injectionPoint) {
|
163 | injectionPoint.appendChild(script);
|
164 | } else {
|
165 | (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.error('Not injecting report dialog. No injection point found in HTML');
|
166 | }
|
167 | }
|
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 | function lastEventId() {
|
175 | return getCurrentHub().lastEventId();
|
176 | }
|
177 |
|
178 |
|
179 |
|
180 |
|
181 |
|
182 | function forceLoad() {
|
183 |
|
184 | }
|
185 |
|
186 |
|
187 |
|
188 |
|
189 |
|
190 | function onLoad(callback) {
|
191 | callback();
|
192 | }
|
193 |
|
194 |
|
195 |
|
196 |
|
197 |
|
198 |
|
199 |
|
200 |
|
201 |
|
202 | function flush(timeout) {
|
203 | const client = getCurrentHub().getClient();
|
204 | if (client) {
|
205 | return client.flush(timeout);
|
206 | }
|
207 | (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.warn('Cannot flush events. No client defined.');
|
208 | return resolvedSyncPromise(false);
|
209 | }
|
210 |
|
211 |
|
212 |
|
213 |
|
214 |
|
215 |
|
216 |
|
217 |
|
218 |
|
219 | function close(timeout) {
|
220 | const client = getCurrentHub().getClient();
|
221 | if (client) {
|
222 | return client.close(timeout);
|
223 | }
|
224 | (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.warn('Cannot flush events and disable SDK. No client defined.');
|
225 | return resolvedSyncPromise(false);
|
226 | }
|
227 |
|
228 |
|
229 |
|
230 |
|
231 |
|
232 |
|
233 |
|
234 |
|
235 |
|
236 | function wrap(fn) {
|
237 | return wrap$1(fn)();
|
238 | }
|
239 |
|
240 | function startSessionOnHub(hub) {
|
241 | hub.startSession({ ignoreDuration: true });
|
242 | hub.captureSession();
|
243 | }
|
244 |
|
245 |
|
246 |
|
247 |
|
248 | function startSessionTracking() {
|
249 | if (typeof WINDOW.document === 'undefined') {
|
250 | (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) &&
|
251 | logger.warn('Session tracking in non-browser environment with @sentry/browser is not supported.');
|
252 | return;
|
253 | }
|
254 |
|
255 | const hub = getCurrentHub();
|
256 |
|
257 |
|
258 |
|
259 |
|
260 |
|
261 |
|
262 |
|
263 | if (!hub.captureSession) {
|
264 | return;
|
265 | }
|
266 |
|
267 |
|
268 |
|
269 |
|
270 |
|
271 | startSessionOnHub(hub);
|
272 |
|
273 |
|
274 | addInstrumentationHandler('history', ({ from, to }) => {
|
275 |
|
276 | if (!(from === undefined || from === to)) {
|
277 | startSessionOnHub(getCurrentHub());
|
278 | }
|
279 | });
|
280 | }
|
281 |
|
282 |
|
283 |
|
284 |
|
285 | function captureUserFeedback(feedback) {
|
286 | const client = getCurrentHub().getClient();
|
287 | if (client) {
|
288 | client.captureUserFeedback(feedback);
|
289 | }
|
290 | }
|
291 |
|
292 | export { captureUserFeedback, close, defaultIntegrations, flush, forceLoad, init, lastEventId, onLoad, showReportDialog, wrap };
|
293 |
|