Skip to content

Commit 6df9533

Browse files
committed
ref(browser): Remove showReportDialog on browser client
1 parent 6267b54 commit 6df9533

File tree

4 files changed

+37
-75
lines changed

4 files changed

+37
-75
lines changed

packages/browser/src/client.ts

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import { BaseClient, Scope, SDK_VERSION } from '@sentry/core';
22
import { ClientOptions, Event, EventHint, Options, Severity, SeverityLevel } from '@sentry/types';
3-
import { getGlobalObject, logger } from '@sentry/utils';
43

54
import { eventFromException, eventFromMessage } from './eventbuilder';
6-
import { IS_DEBUG_BUILD } from './flags';
7-
import { injectReportDialog, ReportDialogOptions } from './helpers';
85
import { Breadcrumbs } from './integrations';
96

107
export interface BaseBrowserOptions {
@@ -62,29 +59,6 @@ export class BrowserClient extends BaseClient<BrowserClientOptions> {
6259
super(options);
6360
}
6461

65-
/**
66-
* Show a report dialog to the user to send feedback to a specific event.
67-
*
68-
* @param options Set individual options for the dialog
69-
*/
70-
public showReportDialog(options: ReportDialogOptions = {}): void {
71-
// doesn't work without a document (React Native)
72-
const document = getGlobalObject<Window>().document;
73-
if (!document) {
74-
return;
75-
}
76-
77-
if (!this._isEnabled()) {
78-
IS_DEBUG_BUILD && logger.error('Trying to call showReportDialog with Sentry Client disabled');
79-
return;
80-
}
81-
82-
injectReportDialog({
83-
...options,
84-
dsn: options.dsn || this.getDsn(),
85-
});
86-
}
87-
8862
/**
8963
* @inheritDoc
9064
*/

packages/browser/src/exports.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,5 @@ export {
5454
opera11StackParser,
5555
winjsStackParser,
5656
} from './stack-parsers';
57-
export { injectReportDialog } from './helpers';
5857
export { defaultIntegrations, forceLoad, init, lastEventId, onLoad, showReportDialog, flush, close, wrap } from './sdk';
5958
export { SDK_NAME } from './version';

packages/browser/src/helpers.ts

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
1-
import { captureException, getReportDialogEndpoint, withScope } from '@sentry/core';
1+
import { captureException, withScope } from '@sentry/core';
22
import { DsnLike, Event as SentryEvent, Mechanism, Scope, WrappedFunction } from '@sentry/types';
33
import {
44
addExceptionMechanism,
55
addExceptionTypeValue,
66
addNonEnumerableProperty,
7-
getGlobalObject,
87
getOriginalFunction,
9-
logger,
108
markFunctionWrapped,
119
} from '@sentry/utils';
1210

13-
import { IS_DEBUG_BUILD } from './flags';
14-
15-
const global = getGlobalObject<Window>();
1611
let ignoreOnError: number = 0;
1712

1813
/**
@@ -182,38 +177,3 @@ export interface ReportDialogOptions {
182177
/** Callback after reportDialog showed up */
183178
onLoad?(): void;
184179
}
185-
186-
/**
187-
* Injects the Report Dialog script
188-
* @hidden
189-
*/
190-
export function injectReportDialog(options: ReportDialogOptions = {}): void {
191-
if (!global.document) {
192-
return;
193-
}
194-
195-
if (!options.eventId) {
196-
IS_DEBUG_BUILD && logger.error('Missing eventId option in showReportDialog call');
197-
return;
198-
}
199-
200-
if (!options.dsn) {
201-
IS_DEBUG_BUILD && logger.error('Missing dsn option in showReportDialog call');
202-
return;
203-
}
204-
205-
const script = global.document.createElement('script');
206-
script.async = true;
207-
script.src = getReportDialogEndpoint(options.dsn, options);
208-
209-
if (options.onLoad) {
210-
// eslint-disable-next-line @typescript-eslint/unbound-method
211-
script.onload = options.onLoad;
212-
}
213-
214-
const injectionPoint = global.document.head || global.document.body;
215-
216-
if (injectionPoint) {
217-
injectionPoint.appendChild(script);
218-
}
219-
}

packages/browser/src/sdk.ts

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
import { getCurrentHub, getIntegrationsToSetup, initAndBind, Integrations as CoreIntegrations } from '@sentry/core';
2-
import { Hub } from '@sentry/types';
1+
import {
2+
getCurrentHub,
3+
getIntegrationsToSetup,
4+
getReportDialogEndpoint,
5+
Hub,
6+
initAndBind,
7+
Integrations as CoreIntegrations,
8+
} from '@sentry/core';
39
import {
410
addInstrumentationHandler,
511
getGlobalObject,
@@ -121,8 +127,19 @@ export function init(options: BrowserOptions = {}): void {
121127
*
122128
* @param options Everything is optional, we try to fetch all info need from the global scope.
123129
*/
124-
export function showReportDialog(options: ReportDialogOptions = {}): void {
125-
const hub = getCurrentHub();
130+
export function showReportDialog(options: ReportDialogOptions = {}, hub: Hub = getCurrentHub()): void {
131+
// doesn't work without a document (React Native)
132+
const global = getGlobalObject<Window>();
133+
if (!global.document) {
134+
IS_DEBUG_BUILD && logger.error('Global document not defined in showReportDialog call');
135+
return;
136+
}
137+
138+
if (!options.dsn) {
139+
IS_DEBUG_BUILD && logger.error('Missing dsn option in showReportDialog call');
140+
return;
141+
}
142+
126143
const scope = hub.getScope();
127144
if (scope) {
128145
options.user = {
@@ -134,9 +151,21 @@ export function showReportDialog(options: ReportDialogOptions = {}): void {
134151
if (!options.eventId) {
135152
options.eventId = hub.lastEventId();
136153
}
137-
const client = hub.getClient<BrowserClient>();
138-
if (client) {
139-
client.showReportDialog(options);
154+
155+
const script = global.document.createElement('script');
156+
script.async = true;
157+
script.src = getReportDialogEndpoint(options.dsn, options);
158+
159+
if (options.onLoad) {
160+
// eslint-disable-next-line @typescript-eslint/unbound-method
161+
script.onload = options.onLoad;
162+
}
163+
164+
const injectionPoint = global.document.head || global.document.body;
165+
if (injectionPoint) {
166+
injectionPoint.appendChild(script);
167+
} else {
168+
IS_DEBUG_BUILD && logger.error('Not injecting report dialog. No injection point found in HTML');
140169
}
141170
}
142171

0 commit comments

Comments
 (0)