Skip to content

Commit 07ab474

Browse files
committed
fix(bundle): Ensure CDN bundles do not overwrite window.Sentry
1 parent 44ef79a commit 07ab474

File tree

5 files changed

+45
-0
lines changed

5 files changed

+45
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
window.sentryOnLoad = function () {
2+
Sentry.init({});
3+
4+
window.__sentryLoaded = true;
5+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Sentry.forceLoad();
2+
3+
Sentry.captureException('Test exception');
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<script>
6+
window.Sentry = {_customThingOnSentry: 'customThingOnSentry' };
7+
</script>
8+
</head>
9+
<body></body>
10+
</html>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { expect } from '@playwright/test';
2+
3+
import { sentryTest } from '../../../../utils/fixtures';
4+
import { envelopeRequestParser, waitForErrorRequestOnUrl } from '../../../../utils/helpers';
5+
6+
sentryTest('keeps data on window.Sentry intact', async ({ getLocalTestUrl, page }) => {
7+
await page.route('https://dsn.ingest.sentry.io/**/*', route => {
8+
return route.fulfill({
9+
status: 200,
10+
contentType: 'application/json',
11+
body: JSON.stringify({ id: 'test-id' }),
12+
});
13+
});
14+
15+
const url = await getLocalTestUrl({ testDir: __dirname });
16+
const req = await waitForErrorRequestOnUrl(page, url);
17+
18+
const eventData = envelopeRequestParser(req);
19+
20+
expect(eventData.message).toBe('Test exception');
21+
22+
const customThingy = await page.evaluate('window.Sentry._customThingOnSentry');
23+
expect(customThingy).toBe('customThingOnSentry');
24+
});

dev-packages/rollup-utils/bundleHelpers.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ export function makeBaseBundleConfig(options) {
4848
output: {
4949
format: 'iife',
5050
name: 'Sentry',
51+
intro: () => {
52+
return 'exports = window.Sentry || {};';
53+
},
5154
},
5255
context: 'window',
5356
plugins: [rrwebBuildPlugin, markAsBrowserBuildPlugin],

0 commit comments

Comments
 (0)