Skip to content

feat(browser): Add onError callback to showReportDialog - #24780

Merged
andreiborza merged 7 commits into
developfrom
ab/report-dialog-on-error
Sep 28, 2026
Merged

andreiborza merged 7 commits into
developfrom
ab/report-dialog-on-error

Conversation

@andreiborza

@andreiborza andreiborza commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

What

showReportDialog accepts a new onError callback. The SDK calls it when the dialog cannot be shown: the dialog script fails to load, or there is no event ID.

Why

Ad blockers or network problems can block the dialog script, and there was no way to detect it. Apps can now tell users why the dialog did not open.

Closes: #24765

Closes: #24765

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread packages/browser/test/index.test.ts
@github-actions

github-actions Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

size-limit report 📦

⚠️ Warning: Base artifact is not the latest one, because the latest workflow run is not done yet. This may lead to incorrect results. Try to re-run all tests to get up to date results.

Path Size % Change Change
@sentry/browser 29.24 kB - -
@sentry/browser - with treeshaking flags 27.5 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 27.4 kB - -
@sentry/browser (incl. Tracing) 51.15 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 51.17 kB - -
@sentry/browser (incl. Tracing, Profiling) 54.18 kB - -
@sentry/browser (incl. Tracing, Replay) 90.76 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 79.86 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 95.46 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 108.41 kB - -
@sentry/browser (incl. Feedback) 46.76 kB - -
@sentry/browser (incl. sendFeedback) 34.3 kB - -
@sentry/browser (incl. FeedbackAsync) 39.41 kB - -
@sentry/browser (incl. Metrics) 30.25 kB - -
@sentry/browser (incl. Logs) 30.51 kB - -
@sentry/browser (incl. Metrics & Logs) 31.18 kB - -
@sentry/react 31.08 kB +0.29% +88 B 🔺
@sentry/react (incl. Tracing) 53.54 kB +0.17% +90 B 🔺
@sentry/vue 36.74 kB - -
@sentry/vue (incl. Tracing) 53.7 kB - -
@sentry/svelte 29.26 kB - -
CDN Bundle 31.02 kB +0.28% +85 B 🔺
CDN Bundle (incl. Tracing) 51.77 kB +0.17% +87 B 🔺
CDN Bundle (incl. Logs, Metrics) 33.29 kB +0.27% +89 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) 53.75 kB +0.16% +85 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) 74 kB +0.12% +85 B 🔺
CDN Bundle (incl. Tracing, Replay) 89.36 kB +0.1% +88 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 91.33 kB +0.1% +87 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 95.53 kB +0.09% +81 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 97.5 kB +0.09% +81 B 🔺
CDN Bundle - uncompressed 91.66 kB +0.29% +259 B 🔺
CDN Bundle (incl. Tracing) - uncompressed 154.03 kB +0.17% +259 B 🔺
CDN Bundle (incl. Logs, Metrics) - uncompressed 98.23 kB +0.27% +259 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 159.99 kB +0.17% +259 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 227.8 kB +0.12% +259 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 273.76 kB +0.1% +259 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 279.7 kB +0.1% +259 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 287.46 kB +0.1% +259 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 293.39 kB +0.09% +259 B 🔺
@sentry/nextjs (client) 55.77 kB - -
@sentry/sveltekit (client) 51.59 kB - -
@sentry/core/server 39.95 kB - -
@sentry/core/browser 13.63 kB - -
@sentry/node 137.13 kB +0.01% +10 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 82.8 kB - -
@sentry/node - without tracing 90.73 kB +0.02% +12 B 🔺
@sentry/node - without channel injection 115.5 kB +0.01% +8 B 🔺
@sentry/aws-serverless 99 kB +0.01% +8 B 🔺
@sentry/cloudflare (withSentry) - minified 206.62 kB - -
@sentry/cloudflare (withSentry) 514.02 kB - -

View base workflow run

@andreiborza

andreiborza commented Sep 28, 2026 •

Copy link
Copy Markdown
Member Author

batman begin

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 1c0b723. Configure here.


if (onError) {
script.onerror = () => {
onError(new Error('Failed to load the report dialog script'));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be prudent to propagate the original error via { cause: ev.error } depending on the compatibility you are targeting.

@andreiborza andreiborza Sep 28, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just tested this and browsers just give back a plain Event here, there's no .error field. That being said, there's one case where the report dialog errors with a 400 that would be lumped in with this hardcoded error message.

}

if (onError) {
script.onerror = () => {

@SimonSchick SimonSchick Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't the error handler need to be registered before src is set? Same for onLoad really.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To the best of my knowledge, the script starts loading only once its attached to the DOM, so when we set these properties makes no difference.

This is different from when you write a script tag directly to the DOM.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, scripts load only when added to the DOM, unlike images.

@andreiborza
andreiborza marked this pull request as ready for review September 28, 2026 09:14
@andreiborza
andreiborza requested a review from a team as a code owner September 28, 2026 09:14
@andreiborza
andreiborza requested review from Lms24, logaretm and msonnb and removed request for a team September 28, 2026 09:14

@Lms24 Lms24 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks reasonable to me, thx!

Comment on lines +43 to +45
DEBUG_BUILD && debug.error('[showReportDialog] No event ID');
onError?.(new Error('No event ID to show the report dialog for'));
return;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

q: The docs say, onError only reports load errors. Wondering if we should adjust docs (probably) or remove the invocation here, wdyt?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the docs in dd22082

Comment on lines +42 to +46
if (!mergedOptions.eventId) {
DEBUG_BUILD && debug.error('[showReportDialog] No event ID');
onError?.(new Error('No event ID to show the report dialog for'));
return;
}

@logaretm logaretm Sep 28, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think rejecting on missing eventId is a bit of a behavior change, probably breaking.

But it never worked in the first place 🤔

EDIT: Never mind, if they don't have the callback then nothing happens. Disregard.

@logaretm logaretm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought it was breaking change for a second but seems good to me.

Comment thread packages/browser/src/report-dialog.ts
@andreiborza
andreiborza merged commit 378cccb into develop Sep 28, 2026
341 checks passed
@andreiborza
andreiborza deleted the ab/report-dialog-on-error branch September 28, 2026 10:30
andreiborza added a commit to getsentry/sentry-docs that referenced this pull request Sep 29, 2026
## DESCRIBE YOUR PR

Document the `showReportDialog({ onError })` callback added in
getsentry/sentry-javascript#24780. Explain the
`Error` argument for a missing event ID or a script-loading failure, and
show how to notify users when the report dialog cannot open. Clarify
that this callback does not handle report-submission errors.

Keep this draft until the SDK change is released, then add the confirmed
minimum JavaScript SDK version before merging. The v7 documentation is
unchanged.

## IS YOUR CHANGE URGENT?

- [ ] Urgent deadline (GA date, etc.): YYYY-MM-DD
- [ ] Other deadline: YYYY-MM-DD
- [x] No deadline: Not urgent, can wait up to 1 week+

<!-- junior-request-attribution:start -->
via Junior system actor `event`.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:slack%3AC0BKK9QLCUA%3A1790585017.857999 -->

--

[View Junior
Session](https://junior-prod.sentry.dev/conversations/slack%3AC0BKK9QLCUA%3A1790585017.857999)
[[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AC0BKK9QLCUA%3A1790585017.857999/?project=4510944073809921)

<!-- junior-session-footer:end -->

---------

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: Andrei Borza <andrei.borza@sentry.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

showReportDialog failure API

5 participants