Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as Sentry from '@sentry/browser';

window.Sentry = Sentry;

// We mock this here to simulate a Chrome browser extension
window.chrome = { runtime: { id: 'mock-extension-id' } };

Sentry.init({
dsn: 'https://[email protected]/1337',
skipBrowserExtensionCheck: true,
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { expect } from '@playwright/test';
import { sentryTest } from '../../../utils/fixtures';

sentryTest(
'initializes inside a Chrome browser extension if `skipBrowserExtensionCheck` is set',
async ({ getLocalTestUrl, page }) => {
const url = await getLocalTestUrl({ testDir: __dirname });
await page.goto(url);

const isInitialized = await page.evaluate(() => {
return !!(window as any).Sentry.isInitialized();
});

expect(isInitialized).toBe(true);
},
);
21 changes: 20 additions & 1 deletion packages/browser/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,26 @@ import { createUserFeedbackEnvelope } from './userfeedback';
*/
export type BrowserOptions = Options<BrowserTransportOptions> &
BrowserClientReplayOptions &
BrowserClientProfilingOptions;
BrowserClientProfilingOptions & {
/**
* Important: Only set this option if you know what you are doing!
*
* By default, the SDK will check if it is initialized in a browser extension
* if you call `Sentry.init`. In case it is, it will stop initialization
* because browser extensions require a different Sentry initialization process:
* https://docs.sentry.io/platforms/javascript/best-practices/shared-environments/
*
* Setting up the SDK in a browser extension with global error monitoring is not recommended
* and will likely flood you with errors from other web sites or extensions. This can heavily
* impact your quota and cause interference with your and other Sentry SDKs in shared environments.
*
* If this check wrongfully flags your setup as a browser extension, you can set this
* option to `true` to skip the check.
*
* @default false
*/
skipBrowserExtensionCheck?: boolean;
};

/**
* Configuration options for the Sentry Browser SDK Client class
Expand Down
2 changes: 1 addition & 1 deletion packages/browser/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ declare const __SENTRY_RELEASE__: string | undefined;
export function init(browserOptions: BrowserOptions = {}): Client | undefined {
const options = applyDefaultOptions(browserOptions);

if (shouldShowBrowserExtensionError()) {
if (!options.skipBrowserExtensionCheck && shouldShowBrowserExtensionError()) {
consoleSandbox(() => {
// eslint-disable-next-line no-console
console.error(
Expand Down
Loading