lencx/ChatGPT · error
[view:main] Failed to get webview window
Error message
[view:main] Failed to get webview window
What it means
Panic from win.get_webview("main") returning None inside the WindowEvent::Resized handler. get_webview(label) is a registry lookup on the Manager trait; it yields None when no webview with that label is currently attached to the window. The "main" webview is added later in setup via win.add_child(main_view, ...), so any Resized event delivered before that add_child completes — or after teardown removes the webview during window close — hits the .expect() and panics on the main thread.
Source
Thrown at src-tauri/src/core/setup.rs:190
if let Err(e) = view.set_position(position) {
eprintln!("[view:position] Failed to set view position: {}", e);
}
if let Err(e) = view.set_size(size) {
eprintln!("[view:size] Failed to set view size: {}", e);
}
};
win.on_window_event(move |event| {
let conf = &AppConf::load(&handle).unwrap();
let ask_mode_height = if conf.ask_mode { ASK_HEIGHT } else { 0.0 };
let ask_height = (scale_factor * ask_mode_height).round() as u32;
if let WindowEvent::Resized(size) = event {
let win = window_clone.lock().unwrap();
let main_view = win
.get_webview("main")
.expect("[view:main] Failed to get webview window");
let titlebar_view = win
.get_webview("titlebar")
.expect("[view:titlebar] Failed to get webview window");
let ask_view = win
.get_webview("ask")
.expect("[view:ask] Failed to get webview window");
#[cfg(target_os = "macos")]
{
set_view_properties(
&main_view,
LogicalPosition::new(0.0, TITLEBAR_HEIGHT),
PhysicalSize::new(
size.width,
size.height - (titlebar_height + ask_height),
),
);
set_view_properties(View on GitHub (pinned to a6de9a8b61)
Solutions
- Replace .expect() with if let Some/let-else and skip the relayout when the webview is not (yet/anymore) present
- Register the on_window_event handler only after all three add_child calls succeed, reducing the startup window
- Deregister the resize logic on WindowEvent::Destroyed, or check event discriminants before touching webviews
- Log the miss at debug level to diagnose lifecycle races without panicking
Example fix
// before
let main_view = win
.get_webview("main")
.expect("[view:main] Failed to get webview window");
// after
let Some(main_view) = win.get_webview("main") else {
eprintln!("[view:main] webview not ready; skipping resize");
return;
}; Defensive patterns
Strategy: type-guard
Validate before calling
// before registering the resize handler
let all_present = ["main", "titlebar", "ask"]
.iter()
.all(|label| win.get_webview(label).is_some());
assert!(all_present, "webviews must be attached before resize handling"); Type guard
fn webviews_attached(win: &tauri::Window) -> bool {
["main", "titlebar", "ask"].iter().all(|l| win.get_webview(l).is_some())
} Try / catch
let Some(main_view) = win.get_webview("main") else {
eprintln!("[view:main] webview not ready; skipping resize");
return;
}; Prevention
- Never .expect() registry lookups inside event handlers — labels come and go with lifecycle
- Register on_window_event after all add_child calls succeed
- Ignore resize work once Destroyed/CloseRequested begins teardown
When it happens
Trigger: A Resized event arriving during startup before add_child(main_view) finishes (async spawn races the main-thread event loop; common on Linux where mapping a window emits Resized immediately); minimize/restore or close sequences where child webviews are destroyed before the window's event handler is disconnected; the add_child at setup.rs:130 failing (its own .unwrap()) so "main" was never registered.
Common situations: Window snapping/tiling on Linux (many Resized events at odd lifecycle moments); app shutdown with a resize in flight; CI/WM environments (i3, sway) that resize windows at map time; tauri v2 multi-webview API where child webviews drop before the parent window's handlers.
Related errors
- [view:ask] Failed to get webview window
- [view:titlebar] Failed to get webview window
- [core:window] Failed to build window
- [core:window] Failed to get window size
- [view:download] Failed to get download directory
AI-assisted analysis of lencx/ChatGPT@a6de9a8b61 (2026-08-16).
Data as JSON: /api/errors/75162a688a92d7ee.
Report an issue: GitHub.