You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/platforms/javascript/common/best-practices/shared-environments.mdx
+11-7Lines changed: 11 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
---
2
-
title: Browser Extensions
2
+
title: Shared Environments / Browser Extensions
3
3
sidebar_order: 50
4
4
description: Learn how to use Sentry in shared environments (for example in browser extensions or VSCode extensions).
5
5
notSupported:
@@ -19,11 +19,11 @@ keywords:
19
19
"NodeClient",
20
20
"shared environment",
21
21
"browser extension",
22
-
"VSCode extension"
22
+
"VSCode extension",
23
23
]
24
24
---
25
25
26
-
When setting up Sentry in a shared environment where multiple Sentry instances may run, for example, in a browser extension or similar, you should **not use `Sentry.init()`**, as this will pollute the global state. If your browser extension uses `Sentry.init()`, and the website the extension is running on also uses Sentry, the extension may send events to the website's Sentry project, or vice versa.
26
+
When setting up Sentry in a shared environment where multiple Sentry instances may run, for example, in a browser extension or plugin architecture, you should **not use `Sentry.init()`**, as this will pollute the global state. If your browser extension uses `Sentry.init()`, and the website the extension is running on also uses Sentry, the extension may send events to the website's Sentry project, or vice versa.
27
27
28
28
For such scenarios, you have to set up a client manually as seen in the example below.
29
29
In addition, you should also avoid adding any integrations that use global state, like `Breadcrumbs` or `GlobalHandlers`. Furthermore, some default integrations that use the global state have to be filtered as in the example below.
@@ -41,8 +41,13 @@ import {
41
41
} from"@sentry/browser";
42
42
43
43
// filter integrations that use the global variable
0 commit comments