zerodevx/svelte-toast

Support page visibility API

Prinzhorn opened this issue · 6 comments

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

Among other things I'm using toasts to display warnings when something didn't work. If you tab out of the browser (or the Electron app in my case) you might miss it.

I don't know how easy this would be to implement. In a perfect world the toasts would pause (progress bar, timers) when document.hidden and continue when it becomes visible again. If that's too complex then an easier approach would be to queue toasts if document.hidden and insert them on visibilitychange.

Oh well, heureka! The pausable feature literally already exists, so it should actually be trivial to pause all toasts when the document becomes invisible. But this should be a separate feature (you might not want pausable via hover but still pause them when the document is invisible). What I'm saying is that the functionality to pause the toast/timers exists and it would just be a second boolean (global, not per toast hover) that triggers it.

Hey, yes it should be quite trivial to add this feature, especially since the pause() and resume() functions are already there. I kind of think this should be the default behaviour actually - notifications should by nature ensure that they're seen.

Will love a PR on this, else I might take a stab at it soon.

Not sure when I have time for it. If you start working on it please assign the issue to yourself so that we don't both do. I'll comment here when I do.

I kind of think this should be the default behaviour actually - notifications should by nature ensure that they're seen.

I agree. And it's hardly a breaking change, I don't think anyone actually cared yet or realized that's how it works. So maybe we don't even need an option to turn it off.

Cool, we'll leave this open for now for tracking - leave a comment when either of us (or anyone else for that matter) starts work on this. Thanks for the suggestion!

I'm working on this!

Nice, ping me for a review when you got the PR up