File tree Expand file tree Collapse file tree 4 files changed +44
-2
lines changed
dev-packages/browser-integration-tests/suites/manual-client/force-init-chrome-extension Expand file tree Collapse file tree 4 files changed +44
-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 ( 'should not initialize when inside a Chrome browser extension' , async ( { getLocalTestUrl, page } ) => {
5
+ const url = await getLocalTestUrl ( { testDir : __dirname } ) ;
6
+ await page . goto ( url ) ;
7
+
8
+ const isInitialized = await page . evaluate ( ( ) => {
9
+ return ! ! ( window as any ) . Sentry . isInitialized ( ) ;
10
+ } ) ;
11
+
12
+ expect ( isInitialized ) . toBe ( true ) ;
13
+ } ) ;
Original file line number Diff line number Diff line change @@ -26,7 +26,25 @@ import { createUserFeedbackEnvelope } from './userfeedback';
26
26
*/
27
27
export type BrowserOptions = Options < BrowserTransportOptions > &
28
28
BrowserClientReplayOptions &
29
- BrowserClientProfilingOptions ;
29
+ BrowserClientProfilingOptions & {
30
+ /**
31
+ * By default, the SDK will check if it is initialized in a browser extension
32
+ * if you call `Sentry.init`. In case it is, it will stop initialization
33
+ * because browser extensions require a different Sentry initialization process:
34
+ * https://docs.sentry.io/platforms/javascript/best-practices/shared-environments/
35
+ *
36
+ * If this check wrongfully flags your setup as a browser extension, you can set this
37
+ * option to `true` to skip the check.
38
+ *
39
+ * Important: Only set this option if you know what you are doing!
40
+ *
41
+ * Setting up the SDK in a browser extension with global error monitoring is not recommended
42
+ * and will likely flood you with errors from other web sites or extensions.
43
+ *
44
+ * @default false
45
+ */
46
+ skipBrowserExtensionCheck ?: boolean ;
47
+ } ;
30
48
31
49
/**
32
50
* 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