Skip to content

Commit 51d87c1

Browse files
mydeashanamatthews
andauthored
feat: Update loader docs to guard against unexisting Sentry.onLoad() (#8248)
--------- Co-authored-by: Shana Matthews <shana.l.matthews@gmail.com>
1 parent cc0288f commit 51d87c1

File tree

14 files changed

+91
-59
lines changed

14 files changed

+91
-59
lines changed

gatsby-ssr.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function SentryLoaderConfig() {
5353
key="sentry-loader-config"
5454
dangerouslySetInnerHTML={{
5555
__html: `
56-
Sentry.onLoad(function() {
56+
window.Sentry && Sentry.onLoad(function() {
5757
Sentry.init({
5858
integrations: [
5959
new Sentry.Replay({

src/platform-includes/configuration/capture-console/javascript.mdx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ Sentry.init({
2222
></script>
2323

2424
<script>
25-
Sentry.onLoad(function () {
26-
Sentry.init({
27-
integrations: [new Sentry.Integrations.CaptureConsole()],
25+
// Check for existence of Sentry in case Ad-blockers block the Sentry Loader Script
26+
window.Sentry &&
27+
Sentry.onLoad(function () {
28+
Sentry.init({
29+
integrations: [new Sentry.Integrations.CaptureConsole()],
30+
});
2831
});
29-
});
3032
</script>
3133
```
3234

src/platform-includes/configuration/contextlines/javascript.mdx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ Sentry.init({
2222
></script>
2323

2424
<script>
25-
Sentry.onLoad(function () {
26-
Sentry.init({
27-
integrations: [new Sentry.Integrations.ContextLines()],
25+
// Check for existence of Sentry in case Ad-blockers block the Sentry Loader Script
26+
window.Sentry &&
27+
Sentry.onLoad(function () {
28+
Sentry.init({
29+
integrations: [new Sentry.Integrations.ContextLines()],
30+
});
2831
});
29-
});
3032
</script>
3133
```
3234

src/platform-includes/configuration/debug/javascript.mdx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ Sentry.init({
2222
></script>
2323

2424
<script>
25-
Sentry.onLoad(function () {
26-
Sentry.init({
27-
integrations: [new Sentry.Integrations.Debug()],
25+
// Check for existence of Sentry in case Ad-blockers block the Sentry Loader Script
26+
window.Sentry &&
27+
Sentry.onLoad(function () {
28+
Sentry.init({
29+
integrations: [new Sentry.Integrations.Debug()],
30+
});
2831
});
29-
});
3032
</script>
3133
```
3234

src/platform-includes/configuration/dedupe/javascript.mdx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ Sentry.init({
2222
></script>
2323

2424
<script>
25-
Sentry.onLoad(function () {
26-
Sentry.init({
27-
integrations: [new Sentry.Integrations.Dedupe()],
25+
// Check for existence of Sentry in case Ad-blockers block the Sentry Loader Script
26+
window.Sentry &&
27+
Sentry.onLoad(function () {
28+
Sentry.init({
29+
integrations: [new Sentry.Integrations.Dedupe()],
30+
});
2831
});
29-
});
3032
</script>
3133
```
3234

src/platform-includes/configuration/enable-pluggable-integrations-lazy/javascript.mdx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,17 @@ Sentry.addIntegration(new ReportingObserver());
2323
></script>
2424

2525
<script>
26-
Sentry.onLoad(function () {
27-
Sentry.init({
28-
integrations: [],
26+
// Check for existence of Sentry in case Ad-blockers block the Sentry Loader Script
27+
window.Sentry &&
28+
Sentry.onLoad(function () {
29+
Sentry.init({
30+
integrations: [],
31+
});
32+
33+
const client = Sentry.getCurrentHub().getClient();
34+
if (client) {
35+
client.addIntegration(new Sentry.Integrations.ReportingObserver());
36+
}
2937
});
3038
3139
Sentry.addIntegration(new Sentry.Integrations.ReportingObserver());

src/platform-includes/configuration/enable-pluggable-integrations/javascript.mdx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ Sentry.init({
2222
></script>
2323

2424
<script>
25-
Sentry.onLoad(function () {
26-
Sentry.init({
27-
integrations: [new Sentry.Integrations.ReportingObserver()],
25+
// Check for existence of Sentry in case Ad-blockers block the Sentry Loader Script
26+
window.Sentry &&
27+
Sentry.onLoad(function () {
28+
Sentry.init({
29+
integrations: [new Sentry.Integrations.ReportingObserver()],
30+
});
2831
});
29-
});
3032
</script>
3133
```
3234

src/platform-includes/configuration/extra-error-data/javascript.mdx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ Sentry.init({
2222
></script>
2323

2424
<script>
25-
Sentry.onLoad(function () {
26-
Sentry.init({
27-
integrations: [new Sentry.Integrations.ExtraErrorData()],
25+
// Check for existence of Sentry in case Ad-blockers block the Sentry Loader Script
26+
window.Sentry &&
27+
Sentry.onLoad(function () {
28+
Sentry.init({
29+
integrations: [new Sentry.Integrations.ExtraErrorData()],
30+
});
2831
});
29-
});
3032
</script>
3133
```
3234

src/platform-includes/configuration/http-client/javascript.mdx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,16 @@ Sentry.init({
2525
></script>
2626

2727
<script>
28-
Sentry.onLoad(function () {
29-
Sentry.init({
30-
integrations: [new Sentry.Integrations.HttpClient()],
31-
32-
// This option is required for capturing headers and cookies.
33-
sendDefaultPii: true,
28+
// Check for existence of Sentry in case Ad-blockers block the Sentry Loader Script
29+
window.Sentry &&
30+
Sentry.onLoad(function () {
31+
Sentry.init({
32+
integrations: [new Sentry.Integrations.HttpClient()],
33+
34+
// This option is required for capturing headers and cookies.
35+
sendDefaultPii: true,
36+
});
3437
});
35-
});
3638
</script>
3739
```
3840

src/platform-includes/configuration/module-metadata/javascript.mdx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ Sentry.init({
1616
></script>
1717

1818
<script>
19-
Sentry.onLoad(function () {
20-
Sentry.init({
21-
integrations: [new Sentry.Integrations.ModuleMetadata()],
19+
// Check for existence of Sentry in case Ad-blockers block the Sentry Loader Script
20+
window.Sentry &&
21+
Sentry.onLoad(function () {
22+
Sentry.init({
23+
integrations: [new Sentry.Integrations.ModuleMetadata()],
24+
});
2225
});
23-
});
2426
</script>
2527
```
2628

0 commit comments

Comments
 (0)