Skip to content

Commit aac25b7

Browse files
committed
fixes
1 parent 10049f7 commit aac25b7

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

packages/browser/src/client.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ export type BrowserOptions = Options<BrowserTransportOptions> &
3434
*/
3535
export type BrowserClientOptions = ClientOptions<BrowserTransportOptions> &
3636
BrowserClientReplayOptions &
37-
BrowserClientProfilingOptions;
37+
BrowserClientProfilingOptions & {
38+
/** If configured, this URL will be used as base URL for lazy loading integration. */
39+
cdnBaseUrl?: string;
40+
};
3841

3942
/**
4043
* The Sentry Browser SDK Client.

packages/browser/src/utils/lazyLoadIntegration.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { SDK_VERSION } from '@sentry/core';
1+
import { SDK_VERSION, getClient } from '@sentry/core';
22
import type { IntegrationFn } from '@sentry/types';
3+
import type { BrowserClient } from '../client';
34
import { 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

Comments
 (0)