1
1
import { 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' ;
5
7
6
- import { BrowserBackend , BrowserOptions } from './backend' ;
7
8
import { injectReportDialog } from './helpers' ;
8
9
import { 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
+ }
9
43
10
44
/**
11
45
* The Sentry Browser SDK Client.
12
46
*
13
47
* @see BrowserOptions for documentation on configuration options.
14
48
* @see SentryClient for usage documentation.
15
49
*/
16
- export class BrowserClient extends BaseClient < BrowserBackend , BrowserOptions > {
50
+ export class BrowserClient extends BaseClient < BrowserOptions > {
17
51
/**
18
52
* Creates a new Browser SDK instance.
19
53
*
@@ -32,7 +66,20 @@ export class BrowserClient extends BaseClient<BrowserBackend, BrowserOptions> {
32
66
version : SDK_VERSION ,
33
67
} ;
34
68
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 ) ;
36
83
}
37
84
38
85
/**
@@ -76,4 +123,26 @@ export class BrowserClient extends BaseClient<BrowserBackend, BrowserOptions> {
76
123
}
77
124
super . _sendEvent ( event ) ;
78
125
}
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
+ }
79
148
}
0 commit comments