File tree 4 files changed +48
-2
lines changed
dev-packages/browser-integration-tests/suites/manual-client/force-init-chrome-extension
4 files changed +48
-2
lines changed Original file line number Diff line number Diff line change
1
+ import * as Sentry from '@sentry/browser' ;
2
+
3
+ window . Sentry = Sentry ;
4
+
5
+ // We mock this here to simulate a Chrome browser extension
6
+ window . chrome = { runtime : { id : 'mock-extension-id' } } ;
7
+
8
+ Sentry . init ( {
9
+ dsn :
'https://[email protected] /1337' ,
10
+ skipBrowserExtensionCheck : true ,
11
+ } ) ;
Original file line number Diff line number Diff line change
1
+ import { expect } from '@playwright/test' ;
2
+ import { sentryTest } from '../../../utils/fixtures' ;
3
+
4
+ sentryTest (
5
+ 'initializes inside a Chrome browser extension if `skipBrowserExtensionCheck` is set' ,
6
+ async ( { getLocalTestUrl, page } ) => {
7
+ const url = await getLocalTestUrl ( { testDir : __dirname } ) ;
8
+ await page . goto ( url ) ;
9
+
10
+ const isInitialized = await page . evaluate ( ( ) => {
11
+ return ! ! ( window as any ) . Sentry . isInitialized ( ) ;
12
+ } ) ;
13
+
14
+ expect ( isInitialized ) . toBe ( true ) ;
15
+ } ,
16
+ ) ;
Original file line number Diff line number Diff line change @@ -26,7 +26,26 @@ import { createUserFeedbackEnvelope } from './userfeedback';
26
26
*/
27
27
export type BrowserOptions = Options < BrowserTransportOptions > &
28
28
BrowserClientReplayOptions &
29
- BrowserClientProfilingOptions ;
29
+ BrowserClientProfilingOptions & {
30
+ /**
31
+ * Important: Only set this option if you know what you are doing!
32
+ *
33
+ * By default, the SDK will check if `Sentry.init` is called in a browser extension.
34
+ * In case it is, it will stop initialization and log a warning
35
+ * because browser extensions require a different Sentry initialization process:
36
+ * https://docs.sentry.io/platforms/javascript/best-practices/shared-environments/
37
+ *
38
+ * Setting up the SDK in a browser extension with global error monitoring is not recommended
39
+ * and will likely flood you with errors from other web sites or extensions. This can heavily
40
+ * impact your quota and cause interference with your and other Sentry SDKs in shared environments.
41
+ *
42
+ * If this check wrongfully flags your setup as a browser extension, you can set this
43
+ * option to `true` to skip the check.
44
+ *
45
+ * @default false
46
+ */
47
+ skipBrowserExtensionCheck ?: boolean ;
48
+ } ;
30
49
31
50
/**
32
51
* Configuration options for the Sentry Browser SDK Client class
Original file line number Diff line number Diff line change @@ -160,7 +160,7 @@ declare const __SENTRY_RELEASE__: string | undefined;
160
160
export function init ( browserOptions : BrowserOptions = { } ) : Client | undefined {
161
161
const options = applyDefaultOptions ( browserOptions ) ;
162
162
163
- if ( shouldShowBrowserExtensionError ( ) ) {
163
+ if ( ! options . skipBrowserExtensionCheck && shouldShowBrowserExtensionError ( ) ) {
164
164
consoleSandbox ( ( ) => {
165
165
// eslint-disable-next-line no-console
166
166
console . error (
You can’t perform that action at this time.
0 commit comments