Skip to content
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: disable background throttling #12181

Open
wants to merge 16 commits into
base: dev
Choose a base branch
from

Conversation

bastiankistner
Copy link

@bastiankistner bastiankistner commented Jan 3, 2025

This PR relates to #5250

It requires a change of wry for which I've opened another PR: tauri-apps/wry#1445

I've added an option disableBackgroundThrottling to allow developers to choose if their view should automatically be throttled / suspended by the browser after a certain time of being hidden or minimised. In the worst case, this default behaviour of browsers can lead to broken applications running in the background.

For instance if a websocket connection is the only reason not to suspend a "tab" and the machine goes into sleep mode and wakes up again, the connection is often lost and the browser won't have any reason to keep the background tab active and therefore unload it, which will not allow the hidden view to "heal" itself.

This default behaviour effectively renders any browser capabilities unusable for long running background processes. One alternative might be moving logic from the frontend to the backend, but browsers have meanwhile become a great choice for local first apps and if the browser already offers the required features easily accessible, why force developers to leave a territory they feel comfortable with?

As of now, this is only available for WebKit based browsers on iOS 17.0+,iPadOS 17.0+,Mac Catalyst 17.0+, macOS 14.0+, visionOS 1.0+ ( see https://developer.apple.com/documentation/webkit/wkpreferences/inactiveschedulingpolicy-swift.enum?language=objc ).

It can be assumed that it will also be implemented for WebView2 (Windows). And it might be that it's already usable for linux and android, although I couldn't find any documentation about it and also cannot test it locally due to a lack of devices.

As an alternative for windows and non-webkit browsers, one can setup a pending WebLock transaction, which, according to the docs, can also keep the browser from suspending it.


I needed to update a snapshot test and am unsure if this is at all related to this change. Please let me know if I did something wrong here.


Pending Tasks

Copy link
Member

@FabianLars FabianLars left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks so much. If nothing major changes in the Wry PR i only have 2 very small comments:

.changes/disable-background-throttling.md Outdated Show resolved Hide resolved
crates/tauri-runtime/src/webview.rs Outdated Show resolved Hide resolved
Copy link
Contributor

github-actions bot commented Jan 6, 2025

Package Changes Through ce3cb33

There are 10 changes which include tauri-cli with minor, @tauri-apps/cli with minor, tauri-build with patch, tauri-runtime with minor, tauri-runtime-wry with minor, tauri-utils with minor, tauri with minor, @tauri-apps/api with minor, tauri-bundler with patch, tauri-driver with patch

Planned Package Versions

The following package releases are the planned based on the context of changes in this pull request.

package current next
@tauri-apps/api 2.2.0 2.3.0
tauri-utils 2.1.1 2.2.0
tauri-bundler 2.2.0 2.2.1
tauri-runtime 2.3.0 2.4.0
tauri-runtime-wry 2.3.0 2.4.0
tauri-codegen 2.0.4 2.0.5
tauri-macros 2.0.4 2.0.5
tauri-plugin 2.0.4 2.0.5
tauri-build 2.0.4 2.0.5
tauri 2.2.0 2.3.0
@tauri-apps/cli 2.2.2 2.3.0
tauri-cli 2.2.2 2.3.0
tauri-driver 2.0.1 2.0.2

Add another change file through the GitHub UI by following this link.


Read about change files or the docs at github.com/jbolda/covector

@bastiankistner
Copy link
Author

@FabianLars I changed the comments according to your suggestions and also updated the wry PR with a version check. Let me know if there is anything else I should do before this PR can be merged.

@bastiankistner
Copy link
Author

I changed the wry version to 0.48.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants