11import { BaseClient , Scope , SDK_VERSION } from '@sentry/core' ;
2- import { Event , EventHint } from '@sentry/types' ;
3- import { getGlobalObject , logger } from '@sentry/utils' ;
4- import { ReportDialogOptions } from '@sentry/transport-base' ;
2+ import { Event , EventHint , Options , Severity } from '@sentry/types' ;
3+ import { getGlobalObject , logger , supportsFetch } from '@sentry/utils' ;
4+ import { NoopTransport , ReportDialogOptions , Transport , TransportOptions } from '@sentry/transport-base' ;
5+ import { FetchTransport } from '@sentry/transport-fetch' ;
6+ import { XHRTransport } from '@sentry/transport-xhr' ;
57
6- import { BrowserBackend , BrowserOptions } from './backend' ;
78import { injectReportDialog } from './helpers' ;
89import { Breadcrumbs } from './integrations' ;
10+ import { eventFromException , eventFromMessage } from './eventbuilder' ;
11+
12+ /**
13+ * Configuration options for the Sentry Browser SDK.
14+ * @see BrowserClient for more information.
15+ */
16+ export interface BrowserOptions extends Options {
17+ /**
18+ * A pattern for error URLs which should exclusively be sent to Sentry.
19+ * This is the opposite of {@link Options.denyUrls}.
20+ * By default, all errors will be sent.
21+ */
22+ allowUrls ?: Array < string | RegExp > ;
23+
24+ /**
25+ * A pattern for error URLs which should not be sent to Sentry.
26+ * To allow certain errors instead, use {@link Options.allowUrls}.
27+ * By default, all errors will be sent.
28+ */
29+ denyUrls ?: Array < string | RegExp > ;
30+
31+ /** @deprecated use {@link Options.allowUrls} instead. */
32+ whitelistUrls ?: Array < string | RegExp > ;
33+
34+ /** @deprecated use {@link Options.denyUrls} instead. */
35+ blacklistUrls ?: Array < string | RegExp > ;
36+
37+ /**
38+ * A flag enabling Sessions Tracking feature.
39+ * By default Sessions Tracking is disabled.
40+ */
41+ autoSessionTracking ?: boolean ;
42+ }
943
1044/**
1145 * The Sentry Browser SDK Client.
1246 *
1347 * @see BrowserOptions for documentation on configuration options.
1448 * @see SentryClient for usage documentation.
1549 */
16- export class BrowserClient extends BaseClient < BrowserBackend , BrowserOptions > {
50+ export class BrowserClient extends BaseClient < BrowserOptions > {
1751 /**
1852 * Creates a new Browser SDK instance.
1953 *
@@ -32,7 +66,20 @@ export class BrowserClient extends BaseClient<BrowserBackend, BrowserOptions> {
3266 version : SDK_VERSION ,
3367 } ;
3468
35- super ( BrowserBackend , options ) ;
69+ super ( options ) ;
70+ }
71+
72+ /**
73+ * @inheritDoc
74+ */
75+ public eventFromException ( exception : unknown , hint ?: EventHint ) : PromiseLike < Event > {
76+ return eventFromException ( this . _options , exception , hint ) ;
77+ }
78+ /**
79+ * @inheritDoc
80+ */
81+ public eventFromMessage ( message : string , level : Severity = Severity . Info , hint ?: EventHint ) : PromiseLike < Event > {
82+ return eventFromMessage ( this . _options , message , level , hint ) ;
3683 }
3784
3885 /**
@@ -76,4 +123,26 @@ export class BrowserClient extends BaseClient<BrowserBackend, BrowserOptions> {
76123 }
77124 super . _sendEvent ( event ) ;
78125 }
126+
127+ protected _setupTransport ( ) : Transport {
128+ // TODO: This whole function should be unnecessary and moved to client construction
129+ if ( ! this . _options . dsn ) {
130+ // We return the noop transport here in case there is no Dsn.
131+ return new NoopTransport ( ) ;
132+ }
133+
134+ const transportOptions : TransportOptions = {
135+ ...this . _options . transportOptions ,
136+ dsn : this . _options . transportOptions ?. dsn ?? this . _options . dsn ,
137+ } ;
138+
139+ if ( this . _options . transport ) {
140+ return new this . _options . transport ( transportOptions ) ;
141+ }
142+
143+ if ( supportsFetch ( ) ) {
144+ return new FetchTransport ( transportOptions ) ;
145+ }
146+ return new XHRTransport ( transportOptions ) ;
147+ }
79148}
0 commit comments