Skip to content

Commit 24409e3

Browse files
authored
ref(browser): Skip browser extension warning in non-debug builds (#15310)
I think it is fair to exclude this here, saving a few bytes...?
1 parent 53de523 commit 24409e3

File tree

4 files changed

+40
-20
lines changed
  • dev-packages/browser-integration-tests
  • packages/browser/src

4 files changed

+40
-20
lines changed

dev-packages/browser-integration-tests/suites/manual-client/skip-init-browser-extension/test.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { expect } from '@playwright/test';
22
import { sentryTest } from '../../../utils/fixtures';
3+
import { hasDebugLogs } from '../../../utils/helpers';
34

45
sentryTest(
56
'should not initialize when inside a Firefox/Safari browser extension',
@@ -18,9 +19,14 @@ sentryTest(
1819
});
1920

2021
expect(isInitialized).toEqual(false);
21-
expect(errorLogs.length).toEqual(1);
22-
expect(errorLogs[0]).toEqual(
23-
'[Sentry] You cannot run Sentry this way in a browser extension, check: https://docs.sentry.io/platforms/javascript/best-practices/browser-extensions/',
24-
);
22+
23+
if (hasDebugLogs()) {
24+
expect(errorLogs.length).toEqual(1);
25+
expect(errorLogs[0]).toEqual(
26+
'[Sentry] You cannot run Sentry this way in a browser extension, check: https://docs.sentry.io/platforms/javascript/best-practices/browser-extensions/',
27+
);
28+
} else {
29+
expect(errorLogs.length).toEqual(0);
30+
}
2531
},
2632
);

dev-packages/browser-integration-tests/suites/manual-client/skip-init-chrome-extension/test.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { expect } from '@playwright/test';
22
import { sentryTest } from '../../../utils/fixtures';
3+
import { hasDebugLogs } from '../../../utils/helpers';
34

45
sentryTest('should not initialize when inside a Chrome browser extension', async ({ getLocalTestUrl, page }) => {
56
const errorLogs: string[] = [];
@@ -16,8 +17,13 @@ sentryTest('should not initialize when inside a Chrome browser extension', async
1617
});
1718

1819
expect(isInitialized).toEqual(false);
19-
expect(errorLogs.length).toEqual(1);
20-
expect(errorLogs[0]).toEqual(
21-
'[Sentry] You cannot run Sentry this way in a browser extension, check: https://docs.sentry.io/platforms/javascript/best-practices/browser-extensions/',
22-
);
20+
21+
if (hasDebugLogs()) {
22+
expect(errorLogs.length).toEqual(1);
23+
expect(errorLogs[0]).toEqual(
24+
'[Sentry] You cannot run Sentry this way in a browser extension, check: https://docs.sentry.io/platforms/javascript/best-practices/browser-extensions/',
25+
);
26+
} else {
27+
expect(errorLogs.length).toEqual(0);
28+
}
2329
});

dev-packages/browser-integration-tests/utils/helpers.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,14 @@ export function shouldSkipFeatureFlagsTest(): boolean {
302302
return bundle != null && !bundle.includes('esm') && !bundle.includes('cjs');
303303
}
304304

305+
/**
306+
* Returns true if the current bundle has debug logs.
307+
*/
308+
export function hasDebugLogs(): boolean {
309+
const bundle = process.env.PW_BUNDLE;
310+
return !bundle?.includes('min');
311+
}
312+
305313
/**
306314
* Waits until a number of requests matching urlRgx at the given URL arrive.
307315
* If the timeout option is configured, this function will abort waiting, even if it hasn't received the configured

packages/browser/src/sdk.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -173,21 +173,21 @@ export function init(browserOptions: BrowserOptions = {}): Client | undefined {
173173
const options = applyDefaultOptions(browserOptions);
174174

175175
if (!options.skipBrowserExtensionCheck && shouldShowBrowserExtensionError()) {
176-
consoleSandbox(() => {
177-
// eslint-disable-next-line no-console
178-
console.error(
179-
'[Sentry] You cannot run Sentry this way in a browser extension, check: https://docs.sentry.io/platforms/javascript/best-practices/browser-extensions/',
180-
);
181-
});
176+
if (DEBUG_BUILD) {
177+
consoleSandbox(() => {
178+
// eslint-disable-next-line no-console
179+
console.error(
180+
'[Sentry] You cannot run Sentry this way in a browser extension, check: https://docs.sentry.io/platforms/javascript/best-practices/browser-extensions/',
181+
);
182+
});
183+
}
182184
return;
183185
}
184186

185-
if (DEBUG_BUILD) {
186-
if (!supportsFetch()) {
187-
logger.warn(
188-
'No Fetch API detected. The Sentry SDK requires a Fetch API compatible environment to send events. Please add a Fetch API polyfill.',
189-
);
190-
}
187+
if (DEBUG_BUILD && !supportsFetch()) {
188+
logger.warn(
189+
'No Fetch API detected. The Sentry SDK requires a Fetch API compatible environment to send events. Please add a Fetch API polyfill.',
190+
);
191191
}
192192
const clientOptions: BrowserClientOptions = {
193193
...options,

0 commit comments

Comments
 (0)