HTML5 game loop when tab is not focused

Hi there,

I’m wondering what happens when we do not have the tab active in an HTML5 build. From my experience, the update() calls seem to stack up and not being called while the tab is not focused, and when you gain focus, many update() calls happen at the same time.

Is it possible to continue having the update() calls while the tab is not focused?

Cheers!

2 Likes

Is this still the case? I am having similar issues, though in my case the updates seem to be either paused or ignored while the tab does not have focus (still doing more tests).

I was hoping the new Run While Iconified setting is the answer, but it doesn’t seem to make a difference on html5?

Is there a fix/workaround?

It’s quite problematic for a multiplayer game. Incoming socket data are still received successfully, but if you call any screen update immediately in response (while the tab is not in focus), they are not really updated on the screen so it becomes out of sync. Potential workaround is to detect focus gained event then refresh the entire screen accordingly, but I’m trying to avoid that route if possible.

That setting is only for desktop. It doesn’t work on mobile and HTML5.

It is worth investigating, I believe it should be possible to run JS even while the tab is not focused but it is throttled (different browsers behave differently). You could make a feature request issue about it. There might be extra technical limitations on WASM, someone who knows more about it or is willing to learn will need to look at it.