1
1
import { ClientLike } from '@sentry/types' ;
2
2
import { captureException , getCarrier , getCurrentClient } from '@sentry/minimal' ;
3
- import { addInstrumentationHandler , getGlobalObject , logger } from '@sentry/utils' ;
3
+ import { addInstrumentationHandler , getGlobalObject , logger , supportsFetch } from '@sentry/utils' ;
4
4
import { Dsn , getReportDialogEndpoint , ReportDialogOptions } from '@sentry/transport-base' ;
5
5
import { InboundFilters } from '@sentry/integration-common-inboundfilters' ;
6
6
import { UserAgent } from '@sentry/integration-browser-useragent' ;
@@ -16,6 +16,8 @@ import { LinkedErrors } from '@sentry/integration-browser-linkederrors';
16
16
import { OnError , OnUnhandledRejection } from '@sentry/integration-browser-globalhandlers' ;
17
17
18
18
import { BrowserClient , BrowserOptions } from './client' ;
19
+ import { FetchTransport } from '@sentry/transport-fetch' ;
20
+ import { XHRTransport } from '@sentry/transport-xhr' ;
19
21
20
22
export const defaultIntegrations = [
21
23
new EventTargetWrap ( ) ,
@@ -91,29 +93,37 @@ export const defaultIntegrations = [
91
93
* @see {@link BrowserOptions } for documentation on configuration options.
92
94
*/
93
95
export function init ( options : BrowserOptions = { } ) : ClientLike {
96
+ const carrier = getCarrier ( ) ;
97
+ const client = initClient ( options ) ;
98
+ carrier . client = client ;
99
+
100
+ if ( options . autoSessionTracking ) {
101
+ startSessionTracking ( client ) ;
102
+ }
103
+
104
+ return client ;
105
+ }
106
+
107
+ export function initClient ( options : BrowserOptions = { } ) : ClientLike {
94
108
if ( options . defaultIntegrations === undefined ) {
95
109
options . defaultIntegrations = defaultIntegrations ;
96
110
}
111
+
97
112
if ( options . release === undefined ) {
98
113
const window = getGlobalObject < Window > ( ) ;
99
114
// This supports the variable that sentry-webpack-plugin injects
100
115
if ( window . SENTRY_RELEASE && window . SENTRY_RELEASE . id ) {
101
116
options . release = window . SENTRY_RELEASE . id ;
102
117
}
103
118
}
119
+
104
120
if ( options . autoSessionTracking === undefined ) {
105
121
options . autoSessionTracking = true ;
106<
8000
/code>
122
}
107
123
108
- const carrier = getCarrier ( ) ;
109
- const client = new BrowserClient ( options ) ;
110
- carrier . client = client ;
124
+ options . transport = options . transport ?? ( supportsFetch ( ) ? FetchTransport : XHRTransport ) ;
111
125
112
- if ( options . autoSessionTracking ) {
113
- startSessionTracking ( client ) ;
114
- }
115
-
116
- return client ;
126
+ return new BrowserClient ( options ) ;
117
127
}
118
128
119
129
/**
0 commit comments