Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
82efc67
Add handler for web content process termination on macOS and iOS
JeffTsang Oct 18, 2025
f39aeb6
Remove redundant closure
JeffTsang Oct 18, 2025
2954c83
Add documentation
JeffTsang Oct 18, 2025
04c64dc
Update .changes
JeffTsang Nov 23, 2025
c848d4b
Merge branch 'dev' into fix/web-content-process-termination
JeffTsang Nov 23, 2025
13bb380
Update .changes
JeffTsang Nov 23, 2025
160d7e2
Merge branch 'dev' into fix/web-content-process-termination
JeffTsang Jan 21, 2026
12d4894
Merge branch 'dev' into fix/web-content-process-termination
JeffTsang Mar 11, 2026
fb41639
Add default handler for web content process termination on iOS
JeffTsang Mar 13, 2026
05daf95
Merge branch 'dev' into fix/web-content-process-termination
JeffTsang Mar 13, 2026
9d087bd
Use navigate instead of reload when recovering from web content proce…
JeffTsang Mar 13, 2026
477e710
Merge branch 'fix/web-content-process-termination' of https://github.…
JeffTsang Mar 13, 2026
b296654
Merge branch 'dev' into fix/web-content-process-termination
JeffTsang Mar 13, 2026
4988d6e
Fix handler in webview window
JeffTsang Mar 17, 2026
c5a9f9d
Reload by default on iOS
JeffTsang Mar 17, 2026
3791c6c
Update .changes
JeffTsang Mar 18, 2026
1bda592
Fix code format
JeffTsang Mar 18, 2026
3e7e738
Add default handler to macOS
JeffTsang Mar 19, 2026
f184c59
Move function to tauri::Builder
JeffTsang Apr 1, 2026
578b7b3
Add comment
JeffTsang Apr 1, 2026
31aef4d
Allow fallback handler
JeffTsang Apr 1, 2026
69d4483
Add os check
JeffTsang Apr 1, 2026
f28ede5
Add os checks to use declarations
JeffTsang Apr 1, 2026
cfa6a38
Fix tests
JeffTsang Apr 1, 2026
e491659
Update comment with platform support
JeffTsang Apr 1, 2026
129f0fb
Simplify default handler logic
JeffTsang Apr 2, 2026
342e25b
Merge branch 'fix/web-content-process-termination' of https://github.…
JeffTsang Apr 2, 2026
23250c0
Fix default handler
JeffTsang Apr 2, 2026
b6fb7ec
Remove extra clone
JeffTsang Apr 3, 2026
7160b46
Fix default handler
JeffTsang Apr 3, 2026
e8991c2
Add logging
JeffTsang Apr 4, 2026
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/web-content-process-termination.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"tauri": "patch:bug"
"tauri-runtime": "patch:bug"
"tauri-runtime-wry": "patch:bug"
---

Add handler for web content process termination on macOS and iOS.
7 changes: 7 additions & 0 deletions crates/tauri-runtime-wry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4929,6 +4929,13 @@ You may have it installed on another user account, but it is not available for t

webview_builder =
webview_builder.with_allow_link_preview(webview_attributes.allow_link_preview);

if let Some(on_web_content_process_terminate_handler) =
pending.on_web_content_process_terminate_handler
{
webview_builder = webview_builder
.with_on_web_content_process_terminate_handler(on_web_content_process_terminate_handler);
}
}

#[cfg(target_os = "ios")]
Expand Down
8 changes: 8 additions & 0 deletions crates/tauri-runtime/src/webview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ type DocumentTitleChangedHandler = dyn Fn(String) + Send + 'static;

type DownloadHandler = dyn Fn(DownloadEvent) -> bool + Send + Sync;

#[cfg(any(target_os = "macos", target_os = "ios"))]
type OnWebContentProcessTerminateHandler = dyn Fn() + Send;

#[cfg(target_os = "ios")]
type InputAccessoryViewBuilderFn = dyn Fn(&objc2_ui_kit::UIView) -> Option<objc2::rc::Retained<objc2_ui_kit::UIView>>
+ Send
Expand Down Expand Up @@ -225,6 +228,9 @@ pub struct PendingWebview<T: UserEvent, R: Runtime<T>> {
pub on_page_load_handler: Option<Box<OnPageLoadHandler>>,

pub download_handler: Option<Arc<DownloadHandler>>,

#[cfg(any(target_os = "macos", target_os = "ios"))]
pub on_web_content_process_terminate_handler: Option<Box<OnWebContentProcessTerminateHandler>>,
}

impl<T: UserEvent, R: Runtime<T>> PendingWebview<T, R> {
Expand All @@ -251,6 +257,8 @@ impl<T: UserEvent, R: Runtime<T>> PendingWebview<T, R> {
web_resource_request_handler: None,
on_page_load_handler: None,
download_handler: None,
#[cfg(any(target_os = "macos", target_os = "ios"))]
on_web_content_process_terminate_handler: None,
})
}
}
Expand Down
40 changes: 40 additions & 0 deletions crates/tauri/src/webview/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ pub(crate) type UriSchemeProtocolHandler =
pub(crate) type OnPageLoad<R> = dyn Fn(Webview<R>, PageLoadPayload<'_>) + Send + Sync + 'static;
pub(crate) type OnDocumentTitleChanged<R> = dyn Fn(Webview<R>, String) + Send + 'static;
pub(crate) type DownloadHandler<R> = dyn Fn(Webview<R>, DownloadEvent<'_>) -> bool + Send + Sync;
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) type OnWebContentProcessTerminateHandler<R> = dyn Fn(Webview<R>) + Send;

#[derive(Clone, Serialize)]
pub(crate) struct CreatedEvent {
Expand Down Expand Up @@ -278,6 +280,9 @@ unstable_struct!(
pub(crate) on_page_load_handler: Option<Box<OnPageLoad<R>>>,
pub(crate) document_title_changed_handler: Option<Box<OnDocumentTitleChanged<R>>>,
pub(crate) download_handler: Option<Arc<DownloadHandler<R>>>,
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) on_web_content_process_terminate_handler:
Option<Box<OnWebContentProcessTerminateHandler<R>>>,
}
);

Expand Down Expand Up @@ -356,6 +361,8 @@ async fn create_window(app: tauri::AppHandle) {
on_page_load_handler: None,
document_title_changed_handler: None,
download_handler: None,
#[cfg(any(target_os = "macos", target_os = "ios"))]
on_web_content_process_terminate_handler: None,
}
}

Expand Down Expand Up @@ -435,6 +442,8 @@ async fn create_window(app: tauri::AppHandle) {
on_page_load_handler: None,
document_title_changed_handler: None,
download_handler: None,
#[cfg(any(target_os = "macos", target_os = "ios"))]
on_web_content_process_terminate_handler: None,
}
}

Expand Down Expand Up @@ -697,6 +706,22 @@ tauri::Builder::default()
self
}

/// Defines a closure to be executed when the web content process terminates.
///
/// ## Platform-specific
///
/// - **Linux / Windows / Android:** Unsupported.
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub fn on_web_content_process_terminate<F: Fn(Webview<R>) + Send + 'static>(
mut self,
f: F,
) -> Self {
self
.on_web_content_process_terminate_handler
.replace(Box::new(f));
self
}

pub(crate) fn into_pending_webview<M: Manager<R>>(
mut self,
manager: &M,
Expand Down Expand Up @@ -776,6 +801,21 @@ tauri::Builder::default()
}
}));

#[cfg(any(target_os = "macos", target_os = "ios"))]
if let Some(on_web_content_process_terminate_handler) =
self.on_web_content_process_terminate_handler.take()
{
let label = pending.label.clone();
let manager = manager.manager_owned();
pending
.on_web_content_process_terminate_handler
.replace(Box::new(move || {
if let Some(w) = manager.get_webview(&label) {
on_web_content_process_terminate_handler(w);
}
}));
}

manager
.manager()
.webview
Expand Down
14 changes: 14 additions & 0 deletions crates/tauri/src/webview/webview_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,20 @@ tauri::Builder::default()
self
}

/// Defines a closure to be executed when the web content process terminates.
///
/// ## Platform-specific
///
/// - **Linux / Windows / Android:** Unsupported.
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub fn on_web_content_process_terminate<F: Fn(Webview<R>) + Send + 'static>(

@velocitysystems velocitysystems Mar 11, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: webViewWebContentProcessDidTerminate is the name of the underlying WebKit API. I see that on_web_content_process_terminate is the naming used in WRY, but ideally this should follow the same naming as WebKit.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

When I was naming the function for wry, I opted for the shorter name because it meant the same thing. I would have kept the original name if there was a webViewWebContentProcessWillTerminate event.

mut self,
f: F,
) -> Self {
self.webview_builder = self.webview_builder.on_web_content_process_terminate(f);
self
}

/// Creates a new window.
pub fn build(self) -> crate::Result<WebviewWindow<R>> {
let (window, webview) = self.window_builder.with_webview(self.webview_builder)?;
Expand Down