Skip to content

Commit 35f8a2f

Browse files
Lms24coolguyzone
andauthored
feat(js): Add skipBrowserExtensionCheck documentation (#11693)
adds documentation for a new SDK option introduced in getsentry/sentry-javascript#14147 --------- Co-authored-by: Alex Krawiec <[email protected]>
1 parent 27cba70 commit 35f8a2f

File tree

1 file changed

+37
-10
lines changed

1 file changed

+37
-10
lines changed

docs/platforms/javascript/common/best-practices/shared-environments.mdx

+37-10
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,18 @@ These best practices are relevant for you if you set up Sentry in one of the fol
3939
- Libraries
4040
- Any other scenario where you might have multiple Sentry instances running in the same environment
4141

42-
<Note>
42+
<Alert level="danger">
4343

4444
When setting up Sentry in a shared environment where multiple Sentry instances may run, you should **not use `Sentry.init()`**, as this will pollute the global state. If your browser extension uses `Sentry.init()`, and a website also uses Sentry, the extension may send events to the website's Sentry project, or vice versa.
4545

46-
</ Note>
46+
</ Alert>
4747

48-
For such scenarios, you have to set up a client manually as seen in the example below.
49-
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.
50-
As a rule of thumb, it's best to avoid using any integrations and to rely on manual capture of errors only in such scenarios.
48+
## Shared Environment Setup
5149

50+
For the use cases listed above, set up a client manually as seen in the example below.
51+
In addition, avoid adding any integrations that use global state, like `Breadcrumbs` or `GlobalHandlers`.
52+
Furthermore, some default integrations that use the global state have to be filtered as in the example below.
53+
In these scenarios, it's a best practice to avoid using any integrations and to rely on manually capturing errors.
5254

5355
```javascript
5456
import {
@@ -61,11 +63,9 @@ import {
6163

6264
// filter integrations that use the global variable
6365
const integrations = getDefaultIntegrations({}).filter((defaultIntegration) => {
64-
return ![
65-
"BrowserApiErrors",
66-
"Breadcrumbs",
67-
"GlobalHandlers",
68-
].includes(defaultIntegration.name);
66+
return !["BrowserApiErrors", "Breadcrumbs", "GlobalHandlers"].includes(
67+
defaultIntegration.name
68+
);
6969
});
7070

7171
const client = new BrowserClient({
@@ -104,3 +104,30 @@ If you notice that Sentry is not capturing error events from the browser extensi
104104
You can disable that by going to your **Project Settings > Inbound Filters** and disabling filtering out errors known to be caused by browser extensions.
105105

106106
Read more about Inbound Filters in the product documentation under [Inbound filters](/concepts/data-management/filtering/#inbound-data-filters).
107+
108+
## Skipping the Browser Extension Check
109+
110+
_Available in all browser-based SDKs since version `8.37.0`_
111+
112+
If for some reason, the SDK wrongfully detects that it's initialized in a browser extension, you can skip the check by specifying the `skipBrowserExtensionCheck` option when initializing the SDK:
113+
114+
```javascript
115+
import * as Sentry from "@sentry/browser";
116+
117+
Sentry.init({
118+
dsn: "___PUBLIC_DSN___",
119+
skipBrowserExtensionCheck: true,
120+
// ...
121+
});
122+
```
123+
124+
<Alert level="danger">
125+
126+
You shouldn't use this option if you're in fact using the SDK in a browser extension or another shared environment.
127+
Initializing the SDK via `Sentry.init` has no advantages over manually setting up the client and scope as described on this page.
128+
You'd risk quota increases with unactionable issues, interference with other Sentry SDKs, and data leakage by doing so.
129+
130+
</Alert>
131+
132+
This option is purely meant as an escape hatch if our browser extension check is incorrectly detecting a browser extension.
133+
An example for this might be a cross-platform application framework that exposes similar global APIs like browser extensions.

0 commit comments

Comments
 (0)