designcourse icon indicating copy to clipboard operation
designcourse copied to clipboard

🐛 RUM Events cease to publish when beforeUnload event is fired

Open sukhpreet96 opened this issue 1 year ago • 3 comments
trafficstars

Describe the bug When beforeUnload event is fired, the RUM logs cease to publish. beforeUnload displays a browser modal which prompts the user to leave or stay on the page. In browser-sdk code we are already stopping the RUM events. This should not actually stop the RUM events or logs on before Unload but actually it should be on unload.

To Reproduce Steps to reproduce the behavior:

  1. fire beforeUnload event
  2. choose to stay on tab
  3. RUM events would stop publishing Expected behavior The RUM events should keep publishing during beforeUnload and they should actually stop on unload event

sukhpreet96 avatar Sep 23 '24 17:09 sukhpreet96

Pull request to fix this issue https://github.com/DataDog/browser-sdk/pull/3033 @BenoitZugmeyer @amortemousque Requesting a kind review please 🙏

sukhpreet96 avatar Sep 23 '24 18:09 sukhpreet96

Hi @sukhpreet96 ,

Thank you for reaching out.

The collection stopping at beforeUnload indeed has some known limitations and we have received your feature request. Yet, unload is not reliable and is deprecated (cf MDN) in favor of pagehide. Hence, we have been looking at different alternatives to beforeUnload or unload to better detect when the page is gone.

Internally, we are having active discussion on this topic and we will keep you updated.

cy-moi avatar Sep 24 '24 09:09 cy-moi

@cy-moi Thanks for your consideration! You might be interested in sendBeacon https://developer.mozilla.org/en-US/docs/Web/API/Navigator/sendBeacon, Refer "Avoid unload and beforeunload" section. This looks promising for usecases like this one

sukhpreet96 avatar Sep 24 '24 14:09 sukhpreet96

This was fixed in v6.6.2 released in March 27! We flush both at beforeunload and pagehide now.

BenoitZugmeyer avatar Apr 30 '25 14:04 BenoitZugmeyer