Detect when browser is hidden

As for documentation on modern browser when a page is inactive an hidden/pause event should be raised. I tried :

this.events.on(‘hidden’,()=>{
console.log(‘hidden’)
})

this.events.on(‘pause’,()=>{
console.log(‘pause’)
})
But it seems that these events never get called (“this” is the GameScene) whilst the pre-render and render events are fired. So how can detect when window is hidden or inactive. Thank you

Hi,

Try with ‘blur’ and ‘focus’
https://newdocs.phaser.io/docs/3.60.0/Phaser.Core.Events

1 Like

I tried both but none is fired while

> document.addEventListener('visibilitychange', () => {
> 			if (document.hidden) {....

is working, what am i doing wrong?

These are emitted from this.game.events, not this.events (from a scene).