1- import { SDK_VERSION } from '@sentry/core' ;
1+ import { SDK_VERSION , getClient } from '@sentry/core' ;
22import type { IntegrationFn } from '@sentry/types' ;
3+ import type { BrowserClient } from '../client' ;
34import { WINDOW } from '../helpers' ;
45
56// This is a map of integration function method to bundle file name.
@@ -36,32 +37,26 @@ export async function lazyLoadIntegration(name: keyof typeof LazyLoadableIntegra
3637
3738 // Bail if the integration already exists
3839 const existing = WindowWithMaybeIntegration . Sentry [ name ] ;
39- console . log ( { existing } ) ;
4040 if ( typeof existing === 'function' ) {
4141 return existing ;
4242 }
4343
44- const url = `https://browser.sentry-cdn.com/${ SDK_VERSION } /${ bundle } .min.js` ;
45-
44+ const url = getScriptURL ( bundle ) ;
4645 const script = WINDOW . document . createElement ( 'script' ) ;
4746 script . src = url ;
4847 script . crossOrigin = 'anonymous' ;
4948
50- console . log ( url ) ;
51-
5249 const waitForLoad = new Promise < void > ( ( resolve , reject ) => {
5350 script . addEventListener (
5451 'load' ,
5552 ( ) => {
56- console . log ( 'LOADED!' ) ;
5753 resolve ( ) ;
5854 } ,
5955 { once : true , passive : true } ,
6056 ) ;
6157 script . addEventListener (
6258 'error' ,
6359 error => {
64- console . error ( error ) ;
6560 reject ( error ) ;
6661 } ,
6762 { once : true , passive : true } ,
@@ -70,10 +65,6 @@ export async function lazyLoadIntegration(name: keyof typeof LazyLoadableIntegra
7065
7166 WINDOW . document . body . appendChild ( script ) ;
7267
73- console . log ( WINDOW . document . body . innerHTML ) ;
74-
75- console . log ( 'start waiting....' ) ;
76-
7768 try {
7869 await waitForLoad ;
7970 } catch {
@@ -88,3 +79,11 @@ export async function lazyLoadIntegration(name: keyof typeof LazyLoadableIntegra
8879
8980 return integrationFn ;
9081}
82+
83+ function getScriptURL ( bundle : string ) : string {
84+ const client = getClient < BrowserClient > ( ) ;
85+ const options = client && client . getOptions ( ) ;
86+ const baseURL = ( options && options . cdnBaseUrl ) || 'https://browser.sentry-cdn.com' ;
87+
88+ return new URL ( `/${ SDK_VERSION } /${ bundle } .min.js` , baseURL ) . toString ( ) ;
89+ }
0 commit comments