How to detect if the game is unfocused in the browser [SOLVED]

Hello,

Have you tried get_window().has_focus() ?
It’s works on web. Here is a basic example:

func _ready() -> void:
	get_window().focus_entered.connect(_on_window_focus_entered)
	get_window().focus_exited.connect(_on_window_focus_exited)


func _on_window_focus_entered() -> void:
	AudioServer.set_bus_mute(0, false)


func _on_window_focus_exited() -> void:
	AudioServer.set_bus_mute(0, true)

See Node.get_window() and Window.

4 Likes