1
- import { SDK_VERSION } from '@sentry/core' ;
1
+ import { SDK_VERSION , getClient } from '@sentry/core' ;
2
2
import type { IntegrationFn } from '@sentry/types' ;
3
+ import type { BrowserClient } from '../client' ;
3
4
import { WINDOW } from '../helpers' ;
4
5
5
6
// This is a map of integration function method to bundle file name.
@@ -36,32 +37,26 @@ export async function lazyLoadIntegration(name: keyof typeof LazyLoadableIntegra
36
37
37
38
// Bail if the integration already exists
38
39
const existing = WindowWithMaybeIntegration . Sentry [ name ] ;
39
- console . log ( { existing } ) ;
40
40
if ( typeof existing === 'function' ) {
41
41
return existing ;
42
42
}
43
43
44
- const url = `https://browser.sentry-cdn.com/${ SDK_VERSION } /${ bundle } .min.js` ;
45
-
44
+ const url = getScriptURL ( bundle ) ;
46
45
const script = WINDOW . document . createElement ( 'script' ) ;
47
46
script . src = url ;
48
47
script . crossOrigin = 'anonymous' ;
49
48
50
- console . log ( url ) ;
51
-
52
49
const waitForLoad = new Promise < void > ( ( resolve , reject ) => {
53
50
script . addEventListener (
54
51
'load' ,
55
52
( ) => {
56
- console . log ( 'LOADED!' ) ;
57
53
resolve ( ) ;
58
54
} ,
59
55
{ once : true , passive : true } ,
60
56
) ;
61
57
script . addEventListener (
62
58
'error' ,
63
59
error => {
64
- console . error ( error ) ;
65
60
reject ( error ) ;
66
61
} ,
67
62
{ once : true , passive : true } ,
@@ -70,10 +65,6 @@ export async function lazyLoadIntegration(name: keyof typeof LazyLoadableIntegra
70
65
71
66
WINDOW . document . body . appendChild ( script ) ;
72
67
73
- console . log ( WINDOW . document . body . innerHTML ) ;
74
-
75
- console . log ( 'start waiting....' ) ;
76
-
77
68
try {
78
69
await waitForLoad ;
79
70
} catch {
@@ -88,3 +79,11 @@ export async function lazyLoadIntegration(name: keyof typeof LazyLoadableIntegra
88
79
89
80
return integrationFn ;
90
81
}
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