Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changes/app-bound-domains.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"tauri": patch:feat
"tauri-runtime": patch:feat
"tauri-runtime-wry": patch:feat
---

Add `WebviewBuilder::limit_navigations_to_app_bound_domains` and `WebviewWindowBuilder::limit_navigations_to_app_bound_domains` only on iOS.
9 changes: 9 additions & 0 deletions crates/tauri-runtime-wry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4688,6 +4688,15 @@ You may have it installed on another user account, but it is not available for t
webview_builder.with_allow_link_preview(webview_attributes.allow_link_preview);
}

#[cfg(target_os = "ios")]
{
if webview_attributes.limit_navigations_to_app_bound_domains {
webview_builder = webview_builder.with_limit_navigations_to_app_bound_domains(
webview_attributes.limit_navigations_to_app_bound_domains,
)
}
}

#[cfg(target_os = "ios")]
{
if let Some(input_accessory_view_builder) = webview_attributes.input_accessory_view_builder {
Expand Down
37 changes: 37 additions & 0 deletions crates/tauri-runtime/src/webview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ pub struct WebviewAttributes {
/// This relies on [`objc2_ui_kit`] which does not provide a stable API yet, so it can receive breaking changes in minor releases.
#[cfg(target_os = "ios")]
pub input_accessory_view_builder: Option<InputAccessoryViewBuilder>,
#[cfg(target_os = "ios")]
pub limit_navigations_to_app_bound_domains: bool,
}

#[cfg(target_os = "ios")]
Expand Down Expand Up @@ -360,6 +362,8 @@ impl WebviewAttributes {
allow_link_preview: true,
#[cfg(target_os = "ios")]
input_accessory_view_builder: None,
#[cfg(target_os = "ios")]
limit_navigations_to_app_bound_domains: false,
}
}

Expand Down Expand Up @@ -598,6 +602,39 @@ impl WebviewAttributes {
self.allow_link_preview = allow_link_preview;
self
}
/// Whether to limit navigations to App-Bound Domains. This is necessary
/// to enable Service Workers on iOS according to [StackOverflow](https://stackoverflow.com/questions/49673399/service-workers-unavailable-in-wkwebview-in-ios-11-3/64155509#64155509).
///
/// Note: If you pass in `true` make sure to add the following to Info.plist
/// in the iOS project:
/// ```xml
/// <plist>
/// <dict>
/// <key>WKAppBoundDomains</key>
/// <array>
/// <string>localhost</string>
/// </array>
/// </dict>
/// </plist>
/// ```
/// You should also add any additional domains which your app requests assets from.
/// Assets served through custom protocols like Tauri's IPC are added to the
/// list automatically. Available on iOS only.
///
/// Default is false.
///
/// See https://webkit.org/blog/10882/app-bound-domains/ and
/// https://developer.apple.com/documentation/webkit/wkwebviewconfiguration/limitsnavigationstoappbounddomains
///
/// ## Platform-specific
///
/// - **Linux / Windows / Android / MacOS:** Unsupported.
#[must_use]
#[cfg(target_os = "ios")]
pub fn limit_navigations_to_app_bound_domains(mut self, limit_navigations: bool) -> Self {
self.limit_navigations_to_app_bound_domains = limit_navigations;
self
}

/// Change the default background throttling behavior.
///
Expand Down
36 changes: 36 additions & 0 deletions crates/tauri/src/webview/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,42 @@ fn main() {
.allow_link_preview(allow_link_preview);
self
}
/// Whether to limit navigations to App-Bound Domains. This is necessary
/// to enable Service Workers on iOS according to [StackOverflow](https://stackoverflow.com/questions/49673399/service-workers-unavailable-in-wkwebview-in-ios-11-3/64155509#64155509).
///
/// Note: If you pass in `true` make sure to add the following to Info.plist
/// in the iOS project:
/// ```xml
/// <plist>
/// <dict>
/// <key>WKAppBoundDomains</key>
/// <array>
/// <string>localhost</string>
/// </array>
/// </dict>
/// </plist>
/// ```
/// You should also add any additional domains which your app requests assets from.
/// Assets served through custom protocols like Tauri's IPC are added to the
/// list automatically. Available on iOS only.
///
/// Default is false.
///
/// See https://webkit.org/blog/10882/app-bound-domains/ and
/// https://developer.apple.com/documentation/webkit/wkwebviewconfiguration/limitsnavigationstoappbounddomains
///
/// ## Platform-specific
///
/// - **Linux / Windows / Android / MacOS:** Unsupported.
#[cfg(target_os = "ios")]
#[must_use]
pub fn limit_navigations_to_app_bound_domains(mut self, limit_navigations: bool) -> Self {
// self.
self.webview_attributes = self
.webview_attributes
.limit_navigations_to_app_bound_domains(limit_navigations);
self
}

/// Allows overriding the the keyboard accessory view on iOS.
/// Returning `None` effectively removes the view.
Expand Down
35 changes: 35 additions & 0 deletions crates/tauri/src/webview/webview_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1177,6 +1177,41 @@ impl<R: Runtime, M: Manager<R>> WebviewWindowBuilder<'_, R, M> {
.with_input_accessory_view_builder(builder);
self
}

/// Whether to limit navigations to App-Bound Domains. This is necessary
/// to enable Service Workers on iOS according to [StackOverflow](https://stackoverflow.com/questions/49673399/service-workers-unavailable-in-wkwebview-in-ios-11-3/64155509#64155509).
///
/// Note: If you pass in `true` make sure to add the following to Info.plist
/// in the iOS project:
/// ```xml
/// <plist>
/// <dict>
/// <key>WKAppBoundDomains</key>
/// <array>
/// <string>localhost</string>
/// </array>
/// </dict>
/// </plist>
/// ```
/// You should also add any additional domains which your app requests assets from.
/// Assets served through custom protocols like Tauri's IPC are added to the
/// list automatically. Available on iOS only.
///
/// Default is false.
///
/// See https://webkit.org/blog/10882/app-bound-domains/ and
/// https://developer.apple.com/documentation/webkit/wkwebviewconfiguration/limitsnavigationstoappbounddomains
///
/// ## Platform-specific
///
/// - **Linux / Windows / Android / MacOS:** Unsupported.
#[cfg(target_os = "ios")]
pub fn limit_navigations_to_app_bound_domains(mut self, limit_navigations: bool) -> Self {
self.webview_builder = self
.webview_builder
.limit_navigations_to_app_bound_domains(limit_navigations);
self
}
}

/// A type that wraps a [`Window`] together with a [`Webview`].
Expand Down