-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feat] Allow disable background throttling #5250
Comments
Sooo, i researched this topic 2 times already. Once for #5147 and a few weeks before that in context of a discord thread. The only thing left that i couldn't figure out (though it didn't look good either) is to try to make it think it's visible and focused by some weird window manipulation, but that's beyond me - cc @amrbashir tldr: Don't wait for this feature :/ |
This only affects Windows or other platforms as well?
On Windows, we don't hide the webview when the window is minimized (although we probably should) and yet the timers are being throttled. So I don't think we can do much here without explicit support in the webviews. |
This question was always asked in the context of Windows only. No idea how the other webiews actually behave tho |
|
Doesn't seem like @chen-gaoyuan's idea about WebSockets and Web Worker works that well. Did anybody solve this issue on their end? |
It looks like macOS recently added support for picking between {throttle, suspend, none}: I'm not sure if this actually works, or is the thing we're looking for, but in theory, setting it to |
Still no option to avoid it? It's blocker for me, maybe needs to migrate to electron, that I don't want :( |
Minimized application should not rely on interval and timers precision. If you really need that behavior, use timers that run in background worker : https://www.npmjs.com/package/worker-timers - this should solve all of your issues. |
FYI: We opted out to use a web socket server that does a heartbeat to a web worker in the browser instead. It's a hack, but it solved it for now. |
Just I make a game, that works online, and there is exists animations :) |
Hi there! I'm building a tauri app that relies on a WebSocket connection. It works fine until I hide my window, which can be unhidden through a tray icon, and put my machine into sleep mode (MacOS). After several minutes, when I wake it up again, the WebSocket connection will not be reestablished unless I unhide the window. Only then will it reconnect. I assume that this is because the connection drops while my machine is sleeping. And when it comes back up, the fact that the connection is lost, will trigger Webkit to fully suspend the tab before the reconnect can happen. I've tried a lot of hacks like having a local WebRTC ping pong, playing a muted audio file, creating an audio on demand with an OscillatorNode or using an infinitely pending WebLock transaction. Nothing worked on MacOS. So I tried to implement a draft for leveraging the In my case the only solution I see is putting everything into a worker. But since I cannot access tauri IPC from within workers, I'd need a local server that could be passed messages and handle them. But I'm also using pglite and several other features that would then have to be moved down to system level. I do agree that tab suspension is a great feature for regular browser users. But in case of apps that are based on tauri, it should be up the developer to decide when to free resources and handle them properly. Otherwise, many of the great features we have at hand with browser capabilities would become unusable for long running applications. The draft for the background throttling can be found here:
This only works for Webkit/MacOS yet. For windows, as mentioned in MicrosoftEdge/WebView2Feedback#1172, there is still no way to handle this properly it seems. But according to https://techcommunity.microsoft.com/discussions/edgeinsiderannouncements/sleeping-tabs-faq/1705434 using a simple Here is a gist without using a framework: https://gist.github.com/bastiankistner/5739d8fc36239113b91ac52711c4101b @FabianLars do you think this would be something that could make it into tauri? If so, do you have any suggestions for improvements before I could open a PR? |
Totaly agree |
Just wanted to mention that I've now tested multiple times if the issue with the dropped connection due to the suspended (hidden) window persists or is finally gone. And I can happily confirm that using the inactivity policy change resolves it perfectly! Would be great if that could be added to tauri. I'm certain there are many things I'd need to add / change but I'm absolutely willing to push this forward! |
@bastiankistner a PR would definitely help. |
I've opened two PRs, one for wry and one for tauri-apps. |
@FabianLars could you please take a look and let us know what's needed to get it merged. Happy new year! |
Describe the problem
When the APP minimizes, the webview timer will be throttling.
Describe the solution you'd like
Electorn has
webPreferences.backgroundThrottling
optionshttps://www.electronjs.org/docs/latest/api/browser-window#new-browserwindowoptions
Alternatives considered
No response
Additional context
Related: electron/electron#1786
The text was updated successfully, but these errors were encountered: