Skip to content

Commit

Permalink
fix(bundle): Ensure CDN bundles do not overwrite window.Sentry (#12580
Browse files Browse the repository at this point in the history
)

v8 portion of #12579
(not that relevant there because no Loader support yet, but still...)
  • Loading branch information
mydea committed Jun 21, 2024
1 parent e9cda97 commit 6e07ec7
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
window.sentryOnLoad = function () {
Sentry.init({});

window.__sentryLoaded = true;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Sentry.forceLoad();

Sentry.captureException('Test exception');
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script>
window.Sentry = {_customThingOnSentry: 'customThingOnSentry' };
</script>
</head>
<body></body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { expect } from '@playwright/test';

import { sentryTest } from '../../../../utils/fixtures';
import { envelopeRequestParser, waitForErrorRequestOnUrl } from '../../../../utils/helpers';

sentryTest('keeps data on window.Sentry intact', async ({ getLocalTestUrl, page }) => {
await page.route('https://dsn.ingest.sentry.io/**/*', route => {
return route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({ id: 'test-id' }),
});
});

const url = await getLocalTestUrl({ testDir: __dirname });
const req = await waitForErrorRequestOnUrl(page, url);

const eventData = envelopeRequestParser(req);

expect(eventData.message).toBe('Test exception');

const customThingy = await page.evaluate('window.Sentry._customThingOnSentry');
expect(customThingy).toBe('customThingOnSentry');
});
3 changes: 3 additions & 0 deletions dev-packages/rollup-utils/bundleHelpers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ export function makeBaseBundleConfig(options) {
output: {
format: 'iife',
name: 'Sentry',
intro: () => {
return 'exports = window.Sentry || {};';
},
},
context: 'window',
plugins: [rrwebBuildPlugin, markAsBrowserBuildPlugin],
Expand Down

0 comments on commit 6e07ec7

Please sign in to comment.