# How to detect when my application is not visible?

**URL:** <https://forum.godotengine.org/t/how-to-detect-when-my-application-is-not-visible/11744>\
**Category:** Archive\
**Created:** [April 19, 2021, 7:55pm UTC](https://forum.godotengine.org/t/how-to-detect-when-my-application-is-not-visible/11744 "2021-04-19T19:55:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://forum.godotengine.org/uploads/default/original/2X/4/4b0a7fa8a6334634b94a13d421f0d99e6f04e21f.svg) [@system](https://forum.godotengine.org/u/system)\
**Post date:** [April 19, 2021, 7:55pm UTC](https://forum.godotengine.org/t/how-to-detect-when-my-application-is-not-visible/11744/1 "2021-04-19T19:55:41Z")

</div>

| | | |
| --- | --- | --- |
| ℹ | **Attention** | Topic was automatically imported from the old Question2Answer platform. |
| 👤 | **Asked&nbsp;By** | dpensky |

How do I detect when my html5 exported game is not visible?  
Like:

- when the user changes to another tab
- when the user has minimized the browser
- when the user alt+tab to another app

I already tried to print all events in \_notification (what). however it appears that no notification is sent in these cases \*sigh\*

thanks in advance

---

<div class="post-metadata">

**Author:** ![system](https://forum.godotengine.org/uploads/default/original/2X/4/4b0a7fa8a6334634b94a13d421f0d99e6f04e21f.svg) [@system](https://forum.godotengine.org/u/system)\
**Post date:** [April 20, 2021, 4:44am UTC](https://forum.godotengine.org/t/how-to-detect-when-my-application-is-not-visible/11744/2 "2021-04-20T04:44:15Z")

</div>

| | | |
| --- | --- | --- |
| 👤 | **Reply From:** | djangocoyote |

All those cases can be handled with MainLoop’s NOTIFICATION\_WM\_FOCUS\_OUT.

```auto
func _notification(what):
    match what:
        MainLoop.NOTIFICATION_WM_FOCUS_OUT:
           #Pause however you want here
        MainLoop.NOTIFICATION_WM_FOCUS_IN:
           #Unpause

```

This works great in the editor, but nothing happens on the HTML5 exported version

my code:

```auto
func _notification(what):
	match what:
		MainLoop.NOTIFICATION_WM_FOCUS_OUT:
			if $background.playing:
				print('pausing background')
				$background.stream_paused = true
		MainLoop.NOTIFICATION_WM_FOCUS_IN:
			if play_background and Settings.is_music_on():
				if $background.stream_paused:
					$background.stream_paused = false
					print('resuming background')

```

dpensky | 2021-04-20 11:56

~~Well… this sucks. I discovered that this notification is only emitted on the Release version and not in the Debug version of the HTML5 exported version for some obscure reason, which is a pain to test~~

dpensky | 2021-04-20 12:40

That’s not the case either. Something else is interfering with this notification.  
Sometimes this works, sometimes don’t.

dpensky | 2021-04-20 13:13
