From b8a0cfa25a141b8938f1e6686f9ae316594d88f2 Mon Sep 17 00:00:00 2001 From: Sylvain Brunerie Date: Sat, 24 Apr 2021 14:20:11 +0200 Subject: [PATCH] =?UTF-8?q?onVisibilityChange=20doesn=E2=80=99t=20react=20?= =?UTF-8?q?to=20switching=20windows?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Alt-Tab doesn’t change the visibilityState. The docs were suggesting that it did (“if the user switches to a different tab or window”). --- src/Browser/Events.elm | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Browser/Events.elm b/src/Browser/Events.elm index 0dec4ec..74d328e 100644 --- a/src/Browser/Events.elm +++ b/src/Browser/Events.elm @@ -209,7 +209,7 @@ onResize func = {-| Subscribe to any visibility changes, like if the user switches to a -different tab or window. When the user looks away, you may want to: +different tab or minimizes the window. When the user looks away, you may want to: - Pause a timer. - Pause an animation. @@ -218,6 +218,11 @@ different tab or window. When the user looks away, you may want to: - Stop polling a server for new information. - Stop waiting for an [`onKeyUp`](#onKeyUp) event. +**Note:** Switching to a different window on a desktop browser will likely not fire the event, +since browsers don’t know if the window is actually obscured or not. See the docs on the +[Page Visibility API](https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API). + + -} onVisibilityChange : (Visibility -> msg) -> Sub msg onVisibilityChange func =