How to Run the Game while the Tab is Inactive?

How to Run the Game while the Tab is Inactive?

hi, the browser won’t like you to do that, so it controls the invocation of requestAnimationFrame and setTimeout, they are normally stopped when your tab is inactive. See MDN:

requestAnimationFrame() calls are paused in most browsers when running in background tabs or hidden <iframe>s in order to improve performance and battery life.

And chrome doc:

Chrome does not call requestAnimationFrame() when a page is in the background. This behavior has been in place since 2011.

In some circumstances, setTimeout may be able to run in a very low frequency. But all in all, you shouldn’t be relying on timer in background tab.

I know some games like idle games wants to use background timer to keep updating things, or keep connection with the network. I suggest you to run batched tasks while the page returning in normal state. The engine really doesn’t have much things to do here.

1 Like

Tried the solution here, there’s a problem, but it is what I’m looking for

I have the same problem where the Game is being pause… I tried the solution you suggested

game.on(Game.EVENT_HIDE, () => {

It’s not working anymore. resume is being called first. then Pause after.

Can you show me a new way of doing this?

Can I get help please.