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

UnloadObserver should know whether the user stayed on the page after prompt #176

Open
vaadin-miki opened this issue Jun 26, 2020 · 5 comments
Labels
enhancement New feature or request help wanted Extra attention is needed
Milestone

Comments

@vaadin-miki
Copy link
Owner

#170 allows querying the user before leaving the page, but there is currently no way to find out whether or not the user stayed on the page (because unload events have no connection to the server).

There probably is a way to find it out, and it would be nice to have it implemented in UnloadObserver.

@vaadin-miki vaadin-miki added enhancement New feature or request help wanted Extra attention is needed labels Jun 26, 2020
@vaadin-miki vaadin-miki added this to the Future milestone Jun 26, 2020
@mperktold
Copy link

mperktold commented Jul 23, 2020

Did you also try using the Beacon API in an unload event handler, as suggested by @Legioth on Vaadin Forum?

@mperktold
Copy link

mperktold commented Jul 27, 2020

I guess using the Beacon API for this is hard because there is no easy way to expose an endpoint to which the Beacon request could be sent.

Probably it would be better/easier to integrate this feature into Vaadin Flow itself.
The client could send the events to the same endpoint and in the same format to the server as usual, only using the Beacon API instead of fetch or XHR.

Maybe this could even be enabled by default and the server should close the UI in response to the unload event.
Then the framework would automatically call the component's onDetach hook, so resource cleanup on tab close or refresh would just work out of the box.

@vaadin-miki
Copy link
Owner Author

@mperktold thanks for feedback! I looked at the Beacon API and there were two reasons why I did not do any further work; my JS skills are less than I would want them to be, plus as you noticed, there is no easy way to ping the server

if you believe this should be a built-in feature of flow, feel free to create a ticket in vaadin/flow repository, but as for now there are no plans to introduce any functionality like this (simply because the usage would be marginal)

@Legioth
Copy link

Legioth commented Aug 13, 2020

I've created an actual running example based on my idea with the Beacon API. See https://vaadin.com/forum/thread/17523194/18399446 for more details.

@vaadin-miki
Copy link
Owner Author

Great! I will adapt this code in one of the next releases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants