Unfortunately web browser specifications do state that
requestAnimationFrame must stop when page is not visible. It is only
intended to enable visible animation.

Your other options are to use a setTimeout loop, or a postMessage-to-self
loop. E.g. the emscripten_set_timeout_loop function in #include
<emscripten/eventloop.h> :
https://github.com/emscripten-core/emscripten/blob/a273ec405f7ab5386373d7263e2b5cb08db80c53/system/include/emscripten/eventloop.h#L20
and
https://github.com/emscripten-core/emscripten/blob/a273ec405f7ab5386373d7263e2b5cb08db80c53/system/include/emscripten/eventloop.h#L24
(that does the postMessage-to-self, however it may not be good for
shipping, because it will consume 100% of the web page)

Chrome begun to aggressively throttling background tabs a few years ago.
See https://developer.chrome.com/blog/timer-throttling-in-chrome-88/

Web Workers are able to run on the background. One way might be to have a
Web Worker implement a regular timer and periodically postMessage to the
main web browser thread to implement a regular loop.

On Tue, Oct 25, 2022 at 9:43 PM Lorenzo Portillo <[email protected]>
wrote:

> Hello,
>
> I'm programming a game loop and I'm trying to find a way to make it work
> normally on browser tab switch, getting the actual delta every frame.
>
> This is the behavior when the browser tab is unselected:
>
> JS *setInterval(loop, 0)* behavior is calling the interval every second
> instead every frame. That returns a delta of ~1000ms.
>
> Then I try to do it with emscripten and I noticed 
> *emscripten_request_animation_frame_loop
> *stops working when I unselect the browser tab. So the delta of my main
> loop returns to the amount of time the tab was unselected. The main loop is
> never called while the tab is unselected.
>
> Is there a way to prevent this and let wasm call the loop function every
> frame even if the browser tab is unselected?
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "emscripten-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/emscripten-discuss/d0704b19-1a60-4c45-b0b2-027aa69bd3b9n%40googlegroups.com
> <https://groups.google.com/d/msgid/emscripten-discuss/d0704b19-1a60-4c45-b0b2-027aa69bd3b9n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/emscripten-discuss/CA%2B6sJ-1bFnkpT4F47kdqd7zDvkHsT4k1%2BBThQbp5SCcvFS2WOw%40mail.gmail.com.

Reply via email to