{"record":{"id":"a5b2248297fc0f03","repo":"lencx/ChatGPT","slug":"view-titlebar-failed-to-get-webview-window","errorCode":null,"errorMessage":"[view:titlebar] Failed to get webview window","messagePattern":"\\[view:titlebar\\] Failed to get webview window","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/src/core/setup.rs","lineNumber":193,"sourceCode":"                    if let Err(e) = view.set_size(size) {\n                        eprintln!(\"[view:size] Failed to set view size: {}\", e);\n                    }\n                };\n\n            win.on_window_event(move |event| {\n                let conf = &AppConf::load(&handle).unwrap();\n                let ask_mode_height = if conf.ask_mode { ASK_HEIGHT } else { 0.0 };\n                let ask_height = (scale_factor * ask_mode_height).round() as u32;\n\n                if let WindowEvent::Resized(size) = event {\n                    let win = window_clone.lock().unwrap();\n\n                    let main_view = win\n                        .get_webview(\"main\")\n                        .expect(\"[view:main] Failed to get webview window\");\n                    let titlebar_view = win\n                        .get_webview(\"titlebar\")\n                        .expect(\"[view:titlebar] Failed to get webview window\");\n                    let ask_view = win\n                        .get_webview(\"ask\")\n                        .expect(\"[view:ask] Failed to get webview window\");\n\n                    #[cfg(target_os = \"macos\")]\n                    {\n                        set_view_properties(\n                            &main_view,\n                            LogicalPosition::new(0.0, TITLEBAR_HEIGHT),\n                            PhysicalSize::new(\n                                size.width,\n                                size.height - (titlebar_height + ask_height),\n                            ),\n                        );\n                        set_view_properties(\n                            &titlebar_view,\n                            LogicalPosition::new(0.0, 0.0),\n                            PhysicalSize::new(size.width, titlebar_height),","sourceCodeStart":175,"sourceCodeEnd":211,"githubUrl":"https://github.com/lencx/ChatGPT/blob/a6de9a8b61077fa63ad5c3ecbe2bc12e0cb4b4b9/src-tauri/src/core/setup.rs#L175-L211","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nlet titlebar_view = win\n    .get_webview(\"titlebar\")\n    .expect(\"[view:titlebar] Failed to get webview window\");\n\n// after\nlet Some(titlebar_view) = win.get_webview(\"titlebar\") else {\n    eprintln!(\"[view:titlebar] webview not ready; skipping resize\");\n    return;\n};","handlingStrategy":"type-guard","validationCode":"// verify the platform-ordered children exist before hooking events\nif !webviews_attached(&win) {\n    eprintln!(\"[setup] skipping resize handler; children missing\");\n    return;\n}","typeGuard":"fn titlebar_attached(win: &tauri::Window) -> bool {\n    win.get_webview(\"titlebar\").is_some()\n}","tryCatchPattern":"let Some(titlebar_view) = win.get_webview(\"titlebar\") else {\n    eprintln!(\"[view:titlebar] webview not ready; skipping resize\");\n    return;\n};","preventionTips":["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"],"tags":["tauri","webview","titlebar","window-events","race-condition","panic"],"backgroundTag":null,"analyzedSha":"a6de9a8b61077fa63ad5c3ecbe2bc12e0cb4b4b9","analyzedAt":"2026-08-16T08:31:13.240Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}