generativefm / generative.fm

A platform for playing generative music in the browser.
https://generative.fm
MIT License
1.59k stars 86 forks source link

Interrupt user leaving site if music is playing #49

Closed alexbainter closed 5 years ago

alexbainter commented 5 years ago

https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onbeforeunload

This prevents users from accidentally closing the site while only mildly annoying users who actually want to leave.

Don't do this on mobile (some devices don't support it anyway).

cdtinney commented 5 years ago

What is the downside (to the user) of accidentally leaving the site? Losing pieces? Is the currently playing piece something that could be stored in localStorage so they can resume if they re-open within a certain period? That would be a less intrusive solution.

alexbainter commented 5 years ago

@cdtinney I had a user email saying they kept accidentally closing out of the site, so this is my short term easy solution for preventing that. This is the same behavior of Google Play Music's web player so I'm comfortable with the intrusiveness.

cdtinney commented 5 years ago

@metalex9 To play devils advocate -- Spotify/YouTube/SoundCloud don't do this

alexbainter commented 5 years ago

Good point but I'm betting that more users will benefit from this behavior than be annoyed be it. Chrome allows you to prevent popups for a site if you really can't stand it. If the site ever warrants a settings page I will allow this to be turned off.