lencx/ChatGPT · error
[view:titlebar] Failed to get webview window
Error message
[view:titlebar] Failed to get webview window
What it means
Panic from win.get_webview("titlebar") returning None in the Resized handler. The titlebar webview is the first child added on macOS but the second on other platforms (setup.rs:149-157), and the handler expects all three labels to exist forever. None is returned before add_child(titlebar_view, ...) completes or after the webview is torn down during window destruction, so a resize at either boundary panics the event handler.
Source
Thrown at src-tauri/src/core/setup.rs:193
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(
&titlebar_view,
LogicalPosition::new(0.0, 0.0),
PhysicalSize::new(size.width, titlebar_height),View on GitHub (pinned to a6de9a8b61)
Solutions
- Use let-else/if-let for all three lookups and skip the relayout when any is missing
- Move handler registration after the platform-specific add_child block so children exist before events are processed
- Skip work on WindowEvent::Destroyed and early-return when size dimensions are degenerate
- Consider fetching all three labels once and bailing out as a group instead of three independent expects
Example fix
// before
let titlebar_view = win
.get_webview("titlebar")
.expect("[view:titlebar] Failed to get webview window");
// after
let Some(titlebar_view) = win.get_webview("titlebar") else {
eprintln!("[view:titlebar] webview not ready; skipping resize");
return;
}; Defensive patterns
Strategy: type-guard
Validate before calling
// verify the platform-ordered children exist before hooking events
if !webviews_attached(&win) {
eprintln!("[setup] skipping resize handler; children missing");
return;
} Type guard
fn titlebar_attached(win: &tauri::Window) -> bool {
win.get_webview("titlebar").is_some()
} Try / catch
let Some(titlebar_view) = win.get_webview("titlebar") else {
eprintln!("[view:titlebar] webview not ready; skipping resize");
return;
}; Prevention
- Remember add_child order differs per OS (titlebar is 2nd on Windows/Linux, 1st on macOS) — guard regardless of order
- Handle all three lookups as one group and bail out together
- Test resize storms (tiling WM, snap layouts) during startup and shutdown
When it happens
Trigger: Resized fired during the gap between window creation and the non-macOS add_child(titlebar_view) call (titlebar is added second there, widening the race); Resized delivered during close/destroy after child webviews are dropped; the titlebar add_child .unwrap() at setup.rs:148/157 having failed so the label never got registered.
Common situations: Tiling WMs and snap layouts emitting Resized at startup/shutdown; the platform-specific add_child ordering difference (macOS adds titlebar first, Windows/Linux add ask first) making the bug appear OS-specific; DPI/scale-factor changes triggering early resize cascades.
Related errors
- [view:main] Failed to get webview window
- [view:ask] 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/a5b2248297fc0f03.
Report an issue: GitHub.