tauri
tauri copied to clipboard
[feat] Allow disable background throttling
Describe the problem
When the APP minimizes, the webview timer will be throttling.
Describe the solution you'd like
Electorn has webPreferences.backgroundThrottling
options
https://www.electronjs.org/docs/latest/api/browser-window#new-browserwindowoptions
Alternatives considered
No response
Additional context
Related: https://github.com/electron/electron/issues/1786
Sooo, i researched this topic 2 times already. Once for #5147 and a few weeks before that in context of a discord thread. And it really doesn't look good. The webviews don't have APIs for this at all and of course we don't have as much control over the engines as electron does -> their solution is irrelevant for us :( Here's the most relevant upstream issue i could find: https://github.com/MicrosoftEdge/WebView2Feedback/issues/1172
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?
try to make it think it's visible and focused by some weird window manipulation
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
Sooo, i researched this topic 2 times already. Once for #5147 and a few weeks before that in context of a discord thread. And it really doesn't look good. The webviews don't have APIs for this at all and of course we don't have as much control over the engines as electron does -> their solution is irrelevant for us :( Here's the most relevant upstream issue i could find: MicrosoftEdge/WebView2Feedback#1172
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 :/ 查了几天资料, 原因就是浏览器将不在前台的页面休眠了, Chromium最长会一分钟才唤醒一次, 导致setInterval不管设置多小的值也要等1分钟执行一次. 现在有几种方案:
- 最简单的方案, 使用Web Worker 中调用setInterval, 然后发送事件通知app. 但是偶尔也会等几秒才唤醒一次Web Worker.
- 保持一个WebSocket连接, 当有网络连接存在时Chromium不会将页面休眠. 这个必须要tauri来实现, 现在无法使用原生的WebSocket! 希望这个问题能够得到完美的解决! 谢谢!
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}: https://developer.apple.com/documentation/webkit/wkpreferences/4173317-inactiveschedulingpolicy
I'm not sure if this actually works, or is the thing we're looking for, but in theory, setting it to .none
in wry
somewhere around the other config logic (https://github.com/tauri-apps/wry/blob/3e3d59cd4f79c21571e503a5bf80d4d54a654a38/src/wkwebview/mod.rs#L457) should work (for macOS).
Still no option to avoid it? It's blocker for me, maybe needs to migrate to electron, that I don't want :(
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.
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.
Just I make a game, that works online, and there is exists animations :)