11import { BaseClient , Scope , SDK_VERSION } from '@sentry/core' ;
2- import { Event , EventHint } from '@sentry/types' ;
3- import { getGlobalObject , logger } from '@sentry/utils' ;
2+ import { Event , EventHint , Options , Severity , Transport } from '@sentry/types' ;
3+ import { getGlobalObject , logger , supportsFetch } from '@sentry/utils' ;
44
5- import { BrowserBackend , BrowserOptions } from './backend ' ;
5+ import { eventFromException , eventFromMessage } from './eventbuilder ' ;
66import { injectReportDialog , ReportDialogOptions } from './helpers' ;
77import { Breadcrumbs } from './integrations' ;
8+ import { FetchTransport , XHRTransport } from './transports' ;
9+
10+ /**
11+ * Configuration options for the Sentry Browser SDK.
12+ * @see BrowserClient for more information.
13+ */
14+ export interface BrowserOptions extends Options {
15+ /**
16+ * A pattern for error URLs which should exclusively be sent to Sentry.
17+ * This is the opposite of {@link Options.denyUrls}.
18+ * By default, all errors will be sent.
19+ */
20+ allowUrls ?: Array < string | RegExp > ;
21+
22+ /**
23+ * A pattern for error URLs which should not be sent to Sentry.
24+ * To allow certain errors instead, use {@link Options.allowUrls}.
25+ * By default, all errors will be sent.
26+ */
27+ denyUrls ?: Array < string | RegExp > ;
28+
29+ /** @deprecated use {@link Options.allowUrls} instead. */
30+ whitelistUrls ?: Array < string | RegExp > ;
31+
32+ /** @deprecated use {@link Options.denyUrls} instead. */
33+ blacklistUrls ?: Array < string | RegExp > ;
34+ }
835
936/**
1037 * The Sentry Browser SDK Client.
1138 *
1239 * @see BrowserOptions for documentation on configuration options.
1340 * @see SentryClient for usage documentation.
1441 */
15- export class BrowserClient extends BaseClient < BrowserBackend , BrowserOptions > {
42+ export class BrowserClient extends BaseClient < BrowserOptions > {
1643 /**
1744 * Creates a new Browser SDK instance.
1845 *
@@ -31,7 +58,21 @@ export class BrowserClient extends BaseClient<BrowserBackend, BrowserOptions> {
3158 version : SDK_VERSION ,
3259 } ;
3360
34- super ( BrowserBackend , options ) ;
61+ super ( options ) ;
62+ }
63+
64+ /**
65+ * @inheritDoc
66+ */
67+ public eventFromException ( exception : unknown , hint ?: EventHint ) : PromiseLike < Event > {
68+ return eventFromException ( this . _options , exception , hint ) ;
69+ }
70+
71+ /**
72+ * @inheritDoc
73+ */
74+ public eventFromMessage ( message : string , level : Severity = Severity . Info , hint ?: EventHint ) : PromiseLike < Event > {
75+ return eventFromMessage ( this . _options , message , level , hint ) ;
3576 }
3677
3778 /**
@@ -57,6 +98,17 @@ export class BrowserClient extends BaseClient<BrowserBackend, BrowserOptions> {
5798 } ) ;
5899 }
59100
101+ /**
102+ * @inheritDoc
103+ */
104+ public sendEvent ( event : Event ) : void {
105+ const integration = this . getIntegration ( Breadcrumbs ) ;
106+ if ( integration ) {
107+ integration . addSentryBreadcrumb ( event ) ;
108+ }
109+ super . sendEvent ( event ) ;
110+ }
111+
60112 /**
61113 * @inheritDoc
62114 */
@@ -68,11 +120,26 @@ export class BrowserClient extends BaseClient<BrowserBackend, BrowserOptions> {
68120 /**
69121 * @inheritDoc
70122 */
71- protected _sendEvent ( event : Event ) : void {
72- const integration = this . getIntegration ( Breadcrumbs ) ;
73- if ( integration ) {
74- integration . addSentryBreadcrumb ( event ) ;
123+ protected _setupTransport ( ) : Transport {
124+ if ( ! this . _options . dsn ) {
125+ // We return the noop transport here in case there is no Dsn.
126+ return super . _setupTransport ( ) ;
127+ }
128+
129+ const transportOptions = {
130+ ...this . _options . transportOptions ,
131+ dsn : this . _options . dsn ,
132+ tunnel : this . _options . tunnel ,
133+ sendClientReports : this . _options . sendClientReports ,
134+ _metadata : this . _options . _metadata ,
135+ } ;
136+
137+ if ( this . _options . transport ) {
138+ return new this . _options . transport ( transportOptions ) ;
139+ }
140+ if ( supportsFetch ( ) ) {
141+ return new FetchTransport ( transportOptions ) ;
75142 }
76- super . _sendEvent ( event ) ;
143+ return new XHRTransport ( transportOptions ) ;
77144 }
78145}
0 commit comments