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

Function showReportDialog

packages/browser/src/report-dialog.ts:11–64  ·  view source on GitHub ↗
(options: ReportDialogOptions = {})

Source from the content-addressed store, hash-verified

9 * @param options Everything is optional, we try to fetch all info need from the current scope.
10 */
11export function showReportDialog(options: ReportDialogOptions = {}): void {
12 const optionalDocument = WINDOW.document as Document | undefined;
13 const injectionPoint = optionalDocument?.head || optionalDocument?.body;
14
15 // doesn't work without a document (React Native)
16 if (!injectionPoint) {
17 DEBUG_BUILD && debug.error('[showReportDialog] Global document not defined');
18 return;
19 }
20
21 const scope = getCurrentScope();
22 const client = getClient();
23 const dsn = client?.getDsn();
24
25 if (!dsn) {
26 DEBUG_BUILD && debug.error('[showReportDialog] DSN not configured');
27 return;
28 }
29
30 const mergedOptions = {
31 ...options,
32 user: {
33 ...scope.getUser(),
34 ...options.user,
35 },
36 eventId: options.eventId || lastEventId(),
37 };
38
39 const script = WINDOW.document.createElement('script');
40 script.async = true;
41 script.crossOrigin = 'anonymous';
42 script.src = getReportDialogEndpoint(dsn, mergedOptions);
43
44 const { onLoad, onClose } = mergedOptions;
45
46 if (onLoad) {
47 script.onload = onLoad;
48 }
49
50 if (onClose) {
51 const reportDialogClosedMessageHandler = (event: MessageEvent): void => {
52 if (event.data === '__sentry_reportdialog_closed__') {
53 try {
54 onClose();
55 } finally {
56 WINDOW.removeEventListener('message', reportDialogClosedMessageHandler);
57 }
58 }
59 };
60 WINDOW.addEventListener('message', reportDialogClosedMessageHandler);
61 }
62
63 injectionPoint.appendChild(script);
64}

Callers 3

index.test.tsFile · 0.90
constructorMethod · 0.90
componentDidCatchMethod · 0.90

Calls 7

getClientFunction · 0.90
lastEventIdFunction · 0.85
getReportDialogEndpointFunction · 0.85
getUserMethod · 0.80
errorMethod · 0.65
addEventListenerMethod · 0.65
getCurrentScopeFunction · 0.50

Tested by

no test coverage detected