{"record":{"id":"93dd9a2f8b7871ef","repo":"zed-industries/zed","slug":"must-be-running-in-a-browser-window-context","errorCode":null,"errorMessage":"must be running in a browser window context","messagePattern":"must be running in a browser window context","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/gpui_web/src/dispatcher.rs","lineNumber":332,"sourceCode":"    fn idle_time_remaining(&self) -> Option<Duration> {\n        if !self.on_main_thread() {\n            return None;\n        }\n        IDLE_DEADLINE.with(|deadline| {\n            deadline\n                .borrow()\n                .as_ref()\n                .map(|deadline| Duration::from_secs_f64(deadline.time_remaining() / 1000.0))\n        })\n    }\n\n    fn now(&self) -> Instant {\n        Instant::now()\n    }\n}\n\nfn browser_window() -> web_sys::Window {\n    web_sys::window().expect(\"must be running in a browser window context\")\n}\n\nfn execute_on_main_thread(window: &web_sys::Window, item: MainThreadItem) {\n    match item {\n        MainThreadItem::Runnable(runnable) => {\n            runnable.run();\n        }\n        MainThreadItem::Idle { runnable, timeout } => {\n            schedule_idle_runnable(window, runnable, timeout);\n        }\n        MainThreadItem::Delayed { runnable, millis } => {\n            let callback = Closure::once_into_js(move || {\n                runnable.run();\n            });\n            window\n                .set_timeout_with_callback_and_timeout_and_arguments_0(\n                    callback.unchecked_ref(),\n                    millis,","sourceCodeStart":314,"sourceCodeEnd":350,"githubUrl":"https://github.com/zed-industries/zed/blob/f4178619acd0d47ea1f76a2025c42962c6d6638c/crates/gpui_web/src/dispatcher.rs#L314-L350","documentation":"Panic in the browser_window() helper: web_sys::window() returned None because the global JS `window` object is absent. In a browser this should always exist; it fails when the code runs in a non-window JS context such as a Web Worker (where self exists but window does not) or a headless/non-DOM runtime. Any main-thread dispatch path hitting this helper panics.","triggerScenarios":"Thrown at crates/gpui_web/src/dispatcher.rs:332 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure dispatcher code is only used on the main thread/context where `window` is defined, not inside a Web Worker","Cache the web_sys::Window reference once at platform startup so later calls cannot hit a missing global","Return Option<Window> from the helper and propagate an error instead of panicking"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"f4178619acd0d47ea1f76a2025c42962c6d6638c","analyzedAt":"2026-08-20T19:29:52.058Z","contentChangedAt":"2026-08-20T19:29:52.058Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}