Skip to content

feat(replay): Send replay data when page is unloaded #6910

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

Closed
wants to merge 1 commit into from

Conversation

mydea
Copy link
Member

@mydea mydea commented Jan 23, 2023

This ties into the changes from here: #6859

Currently, we only send replay data on blur. However, we should also listen to beforeunload, which is called when the page is closed.

This ties into the changes from here: #6859
@mydea mydea added Type: Feature Package: replay Issues related to the Sentry Replay SDK labels Jan 23, 2023
@mydea mydea requested review from billyvg and Lms24 January 23, 2023 16:08
@mydea mydea self-assigned this Jan 23, 2023
@billyvg
Copy link
Member

billyvg commented Jan 23, 2023

@mydea
Copy link
Member Author

mydea commented Jan 23, 2023

We use visibilitychange instead of unload https://github.com/getsentry/sentry-javascript/pull/6910/files#diff-37effab960cdba5170b96d00c73bf14c30c6d856a1c94de4f63fe1a06087bb97R436 -- See https://developer.mozilla.org/en-US/docs/Web/API/Window/pagehide_event#usage_notes

That didn't seem to trigger for me in time - I tried the following on desktop:

  1. Open my test app
  2. Enable "Preserve log" in network tab
  3. Click around in test app (trigger changes)
  4. Go to different page via breadcrumb

Without this change, no request was even tried to be sent. With this change, I see a successful HTTP request in the network tab.

@github-actions
Copy link
Contributor

size-limit report 📦

Path Size
@sentry/browser - ES5 CDN Bundle (gzipped + minified) 19.83 KB (+0.02% 🔺)
@sentry/browser - ES5 CDN Bundle (minified) 61.48 KB (0%)
@sentry/browser - ES6 CDN Bundle (gzipped + minified) 18.5 KB (+0.02% 🔺)
@sentry/browser - ES6 CDN Bundle (minified) 54.79 KB (0%)
@sentry/browser - Webpack (gzipped + minified) 20.22 KB (0%)
@sentry/browser - Webpack (minified) 66.19 KB (0%)
@sentry/react - Webpack (gzipped + minified) 20.25 KB (0%)
@sentry/nextjs Client - Webpack (gzipped + minified) 47.48 KB (0%)
@sentry/browser + @sentry/tracing - ES5 CDN Bundle (gzipped + minified) 26.75 KB (+0.01% 🔺)
@sentry/browser + @sentry/tracing - ES6 CDN Bundle (gzipped + minified) 25.03 KB (+0.01% 🔺)
@sentry/replay ES6 CDN Bundle (gzipped + minified) 43.25 KB (+0.12% 🔺)
@sentry/replay - Webpack (gzipped + minified) 37.97 KB (+0.11% 🔺)
@sentry/browser + @sentry/tracing + @sentry/replay - ES6 CDN Bundle (gzipped + minified) 60.59 KB (+0.07% 🔺)

@billyvg
Copy link
Member

billyvg commented Jan 24, 2023

Moving our Slack conversation back to here... unload will give us an event that pagehide/visibilitychange does not: navigating away from the current page (at least pagehide seems to be less reliable). However, this comes at a cost of disabling bfcache. This is pretty disruptive for our clients as it will impact their customer's experiences and is something we should avoid.

I'm wondering what the overlap between pagehide and visibilitychange are, we may want to consider adding pagehide.

@mydea
Copy link
Member Author

mydea commented Jan 24, 2023

Moving our Slack conversation back to here... unload will give us an event that pagehide/visibilitychange does not: navigating away from the current page (at least pagehide seems to be less reliable). However, this comes at a cost of disabling bfcache. This is pretty disruptive for our clients as it will impact their customer's experiences and is something we should avoid.

I'm wondering what the overlap between pagehide and visibilitychange are, we may want to consider adding pagehide.

In my tests, pagehide was covered by visibility change, so I think it's fine to use only visibilitychange.

Regarding bfcache, I just checked this in chrome, and it seems we are not eligible anyhow because of:

Pages that have inflight fetch() or XHR are not currently eligible for back/forward cache.

Which we'll always have when we try to send stuff before unloading somehow.

@billyvg
Copy link
Member

billyvg commented Jan 24, 2023

But we wont have any inflight requests on unload since we have no listeners for unload?

@mydea
Copy link
Member Author

mydea commented Jan 25, 2023

So we decided that we're OK with this data missing on moving away. Other cases like reloading the tab are handled via visibilitychange.

@mydea mydea closed this Jan 25, 2023
@mydea mydea deleted the fn/send-data-on-unload branch January 25, 2023 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: replay Issues related to the Sentry Replay SDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants