Thanks for the info. I was using workers in a previous version but I wanted to see if emscripten and wasm would allow me to avoid workers.
At the end, there is too much penalty calling javascript functions from Wasm, so finally I decided to keep the game loop in the javascript code. Sobre 31/10/2022 11:12:07, Jukka Jylänki <juj...@gmail.com> escribió: 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 [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 [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/ [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 <bikiniweek...@gmail.com [mailto:bikiniweek...@gmail.com]> 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 emscripten-discuss+unsubscr...@googlegroups.com [mailto:emscripten-discuss+unsubscr...@googlegroups.com]. 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 a topic in the Google Groups "emscripten-discuss" group. To unsubscribe from this topic, visit https://groups.google.com/d/topic/emscripten-discuss/Xp4zDgoyNJc/unsubscribe [https://groups.google.com/d/topic/emscripten-discuss/Xp4zDgoyNJc/unsubscribe]. To unsubscribe from this group and all its topics, send an email to emscripten-discuss+unsubscr...@googlegroups.com [mailto:emscripten-discuss+unsubscr...@googlegroups.com]. To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/CA%2B6sJ-1bFnkpT4F47kdqd7zDvkHsT4k1%2BBThQbp5SCcvFS2WOw%40mail.gmail.com [https://groups.google.com/d/msgid/emscripten-discuss/CA%2B6sJ-1bFnkpT4F47kdqd7zDvkHsT4k1%2BBThQbp5SCcvFS2WOw%40mail.gmail.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 emscripten-discuss+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/Mailbird-5edb01a5-6845-4f4d-aba8-b2bf508f9382%40gmail.com.