Skip to content

Commit ddc0b40

Browse files
feat: Rename browser extension docs -> shared environments (#10356)
Co-authored-by: Stephanie Anderson <stephanie.anderson@sentry.io>
1 parent 9cc5ca5 commit ddc0b40

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

docs/platforms/javascript/common/best-practices/browser-extensions.mdx renamed to docs/platforms/javascript/common/best-practices/shared-environments.mdx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Browser Extensions
2+
title: Shared Environments / Browser Extensions
33
sidebar_order: 50
44
description: Learn how to use Sentry in shared environments (for example in browser extensions or VSCode extensions).
55
notSupported:
@@ -19,11 +19,11 @@ keywords:
1919
"NodeClient",
2020
"shared environment",
2121
"browser extension",
22-
"VSCode extension"
22+
"VSCode extension",
2323
]
2424
---
2525

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.
2727

2828
For such scenarios, you have to set up a client manually as seen in the example below.
2929
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 {
4141
} from "@sentry/browser";
4242

4343
// filter integrations that use the global variable
44-
const integrations = getDefaultIntegrations({}).filter(defaultIntegration => {
45-
return !['BrowserApiErrors', 'TryCatch', 'Breadcrumbs', 'GlobalHandlers'].includes(defaultIntegration.name);
44+
const integrations = getDefaultIntegrations({}).filter((defaultIntegration) => {
45+
return ![
46+
"BrowserApiErrors",
47+
"TryCatch",
48+
"Breadcrumbs",
49+
"GlobalHandlers",
50+
].includes(defaultIntegration.name);
4651
});
4752

4853
const client = new BrowserClient({
@@ -55,11 +60,10 @@ const client = new BrowserClient({
5560
const scope = new Scope();
5661
scope.setClient(client);
5762

58-
client.init() // initializing has to be done after setting the client on the scope
63+
client.init(); // initializing has to be done after setting the client on the scope
5964

6065
// You can capture exceptions manually for this client like this:
6166
scope.captureException(new Error("example"));
62-
6367
```
6468

6569
To make it a bit simpler but somewhat still maintain "Let Sentry handle unhandled errors" you can use the following code:

vercel.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,14 @@
448448
{
449449
"source": "/product/session-replay/(.*)",
450450
"destination": "/product/explore/session-replay/$1"
451+
},
452+
{
453+
"source": "/platforms/javascript/best-practices/browser-extensions/",
454+
"destination": "/platforms/javascript/best-practices/shared-environments/"
455+
},
456+
{
457+
"source": "/platforms/javascript/guides/([^/]*)/best-practices/browser-extensions/",
458+
"destination": "/platforms/javascript/guides/$1/best-practices/shared-environments/"
451459
}
452460
]
453461
}

0 commit comments

Comments
 (0)