11import { ClientLike } from '@sentry/types' ;
22import { captureException , getCarrier , getCurrentClient } from '@sentry/minimal' ;
3- import { addInstrumentationHandler , getGlobalObject , logger } from '@sentry/utils' ;
3+ import { addInstrumentationHandler , getGlobalObject , logger , supportsFetch } from '@sentry/utils' ;
44import { Dsn , getReportDialogEndpoint , ReportDialogOptions } from '@sentry/transport-base' ;
55import { InboundFilters } from '@sentry/integration-common-inboundfilters' ;
66import { UserAgent } from '@sentry/integration-browser-useragent' ;
@@ -16,6 +16,8 @@ import { LinkedErrors } from '@sentry/integration-browser-linkederrors';
1616import { OnError , OnUnhandledRejection } from '@sentry/integration-browser-globalhandlers' ;
1717
1818import { BrowserClient , BrowserOptions } from './client' ;
19+ import { FetchTransport } from '@sentry/transport-fetch' ;
20+ import { XHRTransport } from '@sentry/transport-xhr' ;
1921
2022export const defaultIntegrations = [
2123 new EventTargetWrap ( ) ,
@@ -91,29 +93,37 @@ export const defaultIntegrations = [
9193 * @see {@link BrowserOptions } for documentation on configuration options.
9294 */
9395export 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 {
94108 if ( options . defaultIntegrations === undefined ) {
95109 options . defaultIntegrations = defaultIntegrations ;
96110 }
111+
97112 if ( options . release === undefined ) {
98113 const window = getGlobalObject < Window > ( ) ;
99114 // This supports the variable that sentry-webpack-plugin injects
100115 if ( window . SENTRY_RELEASE && window . SENTRY_RELEASE . id ) {
101116 options . release = window . SENTRY_RELEASE . id ;
102117 }
103118 }
119+
104120 if ( options . autoSessionTracking === undefined ) {
105121 options . autoSessionTracking = true ;
106122 }
107123
108- const carrier = getCarrier ( ) ;
109- const client = new BrowserClient ( options ) ;
110- carrier . client = client ;
124+ options . transport = options . transport ?? ( supportsFetch ( ) ? FetchTransport : XHRTransport ) ;
111125
112- if ( options . autoSessionTracking ) {
113- startSessionTracking ( client ) ;
114- }
115-
116- return client ;
126+ return new BrowserClient ( options ) ;
117127}
118128
119129/**
0 commit comments