{"record":{"id":"8633f5fad693d983","repo":"lencx/ChatGPT","slug":"view-ask-failed-to-get-webview-window","errorCode":null,"errorMessage":"[view:ask] Failed to get webview window","messagePattern":"\\[view:ask\\] Failed to get webview window","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/src/core/setup.rs","lineNumber":196,"sourceCode":"                };\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),\n                        );\n                        set_view_properties(\n                            &ask_view,","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/lencx/ChatGPT/blob/a6de9a8b61077fa63ad5c3ecbe2bc12e0cb4b4b9/src-tauri/src/core/setup.rs#L178-L214","documentation":"Panic from win.get_webview(\"ask\") returning None in the Resized handler. The ask webview (the command palette overlay) is added via add_child(ask_view, ...) — first on non-macOS, last on macOS — and the resize handler unconditionally expects it. Any Resized event outside the lifetime of that webview (before its add_child, or during window destruction once children are dropped) returns None and the .expect() panics inside on_window_event.","triggerScenarios":"A Resized event during startup before add_child(ask_view) registers the label; resize during teardown/close after child webviews are dropped; the ask webview's add_child .unwrap() failing earlier so the label never existed; WM-level resize storms (tiling, maximize on map).","commonSituations":"Same class as the main/titlebar lookups: lifecycle races between the async setup task and the main-thread event loop; also triggered when the ask-mode feature config (conf.ask_mode) changes expected heights while the view set is incomplete.","solutions":["Replace .expect() with let-else and return early from the handler","Guard the whole block: only relayout when get_webview succeeds for main, titlebar, and ask together","Register the event handler after all add_child calls in the platform cfg block","Ignore events once WindowEvent::Destroyed/CloseRequested begins teardown"],"exampleFix":"// before\nlet ask_view = win\n    .get_webview(\"ask\")\n    .expect(\"[view:ask] Failed to get webview window\");\n\n// after\nif let (Some(main_view), Some(titlebar_view), Some(ask_view)) = (\n    win.get_webview(\"main\"),\n    win.get_webview(\"titlebar\"),\n    win.get_webview(\"ask\"),\n) {\n    // set_view_properties(...) calls here\n} else {\n    eprintln!(\"[view:resize] one or more webviews missing; skipping\");\n}","handlingStrategy":"type-guard","validationCode":"// gate the whole relayout on the full view set\nif let (Some(_main), Some(_titlebar), Some(_ask)) = (\n    win.get_webview(\"main\"),\n    win.get_webview(\"titlebar\"),\n    win.get_webview(\"ask\"),\n) {\n    // safe to relayout\n}","typeGuard":"fn webviews_attached(win: &tauri::Window) -> bool {\n    [\"main\", \"titlebar\", \"ask\"].iter().all(|l| win.get_webview(l).is_some())\n}","tryCatchPattern":"if let (Some(main_view), Some(titlebar_view), Some(ask_view)) = (\n    win.get_webview(\"main\"),\n    win.get_webview(\"titlebar\"),\n    win.get_webview(\"ask\"),\n) {\n    // set_view_properties(...) calls\n} else {\n    eprintln!(\"[view:resize] webviews missing; skipping\");\n}","preventionTips":["Make the resize handler idempotent and tolerant of partial view sets","Defer handler registration until after the platform cfg block adds all children","Skip relayout when size.width/height are 0 (minimized) to avoid degenerate layouts"],"tags":["tauri","webview","window-events","race-condition","lifecycle","panic"],"backgroundTag":null,"analyzedSha":"a6de9a8b61077fa63ad5c3ecbe2bc12e0cb4b4b9","analyzedAt":"2026-08-16T08:31:13.240Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}