GithubHelp home page GithubHelp logo

Comments (6)

daxpedda avatar daxpedda commented on August 16, 2024 1

I was investigating if there is an issue in Winit or if Winit can do something here, just dropping my results here.

So my assumption is that the reason why Event::Suspended is only received when going back to the tab is because in general all Winit events in Bevy are cached in handled in WindowEvent::RedrawRequested. But this event has to be handled in the event loop directly and not when WindowEvent::RedrawRequested is reached (which would be in the next browser event loop tick).

Unfortunately, the spec doesn't specify anymore in which case a browser is allowed or not allowed to freeze a page (and discard it afterwards). To prevent browsers based on Chromium (the only engine currently implementing the Page Lifecycle API) from freezing the page, see this document by Chromium outlining their heuristic.

In the future the spec might officially introduce an opt-out method with the Screen Wake Lock API, see WICG/page-lifecycle#31.

from bevy.

Nul-led avatar Nul-led commented on August 16, 2024

Im not really sure if this should be part of bevy to be honest. The solution mentioned uses the fact that web workers aren't throttled by major browsers (unlike timers in content scripts), however this is (as far as im aware) not standardized and up to the browser for implementation. So it is essentially a temporary fix not a solution as browsers could very well change this behavior at any point. Which leads me to believe that it is not a good idea to rely on this in bevy.

However it might be a good idea to run app.update() whenever the browser fires an visibilitychange event.

Additionally my solution relies on unsafe casting and will only work in a single threaded environment so it isn't entirely future proof in that aspect either (see multithreading proposal for WebAssembly).

Tldr;
I believe this should be implemented in an independent crate or at least with an optional feature.

from bevy.

Nul-led avatar Nul-led commented on August 16, 2024

Published https://crates.io/crates/bevy_web_keepalive if someone needs a solution until this is fixed upstream (if this gets fixed at all)

from bevy.

Nul-led avatar Nul-led commented on August 16, 2024

tho @happydpc this might not work for you as this only runs the Main schedule, so the renderer subapp wouldn't be affected.

from bevy.

simbleau avatar simbleau commented on August 16, 2024

Yeah my issues are fixed with that plugin

from bevy.

simbleau avatar simbleau commented on August 16, 2024

In the meantime, for anyone visiting this issue, just use https://crates.io/crates/bevy_web_keepalive

It solves the issue for all browsers by deploying a Web worker which runs the Main schedule once every (configurable) interval when the window is suspended.

from bevy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.