Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add onClose callback (or equiv) to showReportDialog #9433

Closed
phayes opened this issue Nov 2, 2023 · 6 comments · Fixed by getsentry/sentry-docs#8484 or getsentry/sentry#59885
Closed

Comments

@phayes
Copy link

phayes commented Nov 2, 2023

Problem Statement

I want to be able to take an action after a user has closed the report-dialog (opened via showReportDialog).

Specifically, after my javascript application has crashed (gotten into a unknown and likely corrupted state) I pop the report dialog via the showReportDialog. After the user either submits their report or otherwise closes the dialog I want to reload the page.

This is re-opening #758

The solution suggested in the previous issue does not work for three reasons:

  1. There's a race condition on when, exactly, the DOM elements are loaded.
  2. The classes attached to the specified elements are not part of the official API and therefore brittle and prone to change.
  3. This does not solve the issue of the user closing the dialog by simply clicking outside of it.

Solution Brainstorm

An an 'onClose' callback.

@AbhiPrasad
Copy link
Member

Hey @phayes. I can see you left a comment on #758 - you're right that an onClose callback is needed.

PRs are welcome if you're interested in contributing! The report dialog HTML is on the main Sentry site, and the logic to control the report dialog can be seen here:

export function showReportDialog(options: ReportDialogOptions = {}, hub: Hub = getCurrentHub()): void {

@arya-s
Copy link
Contributor

arya-s commented Nov 14, 2023

Hello, original reporter of the issue here.

I took a stab at this over the weekend, please let me know if there's anything else missing.

I created three PRs for this:

Finally, here's a demo project: https://github.com/arya-s/sentry-onclose-report-dialog

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 Nov 14, 2023
@lforst
Copy link
Member

lforst commented Nov 15, 2023

Hi, @arya-s thanks for taking a stab at this. I hope we will get around to reviewing this in a timely manner.

@getsantry getsantry bot removed the status in GitHub Issues with 👀 Nov 15, 2023
arya-s added a commit to arya-s/sentry that referenced this issue Nov 22, 2023
Sends `reportdialog_closed` via window.postMessage to the parent of the
error page embed in preparation of supporting an `onClose` callback in
@sentry/browser `showReportDialog`.

Fixes getsentry/sentry-javascript#9433
arya-s added a commit to arya-s/sentry-javascript that referenced this issue Nov 22, 2023
onurtemizkan pushed a commit that referenced this issue Nov 24, 2023
Adds an `onClose` callback to `showReportDialog`.

The callback is invoked when a `__sentry_reportdialog_closed__`
MessageEvent is received. This is sent from the error page embed via
`window.postMessage` and listened to in the sdk.
@AbhiPrasad
Copy link
Member

Released and documented with https://github.com/getsentry/sentry-javascript/releases/tag/7.82.0. Thanks a lot @arya-s for your contribution.

@arya-s
Copy link
Contributor

arya-s commented Nov 28, 2023

@AbhiPrasad thanks for the guidance and code review :)

@elamperti
Copy link

Thank you @arya-s!!! Great work 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
5 participants