zed-industries/zed · error

must be running in a browser window context

Error message

must be running in a browser window context

What it means

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.

Source

Thrown at crates/gpui_web/src/dispatcher.rs:332

    fn idle_time_remaining(&self) -> Option<Duration> {
        if !self.on_main_thread() {
            return None;
        }
        IDLE_DEADLINE.with(|deadline| {
            deadline
                .borrow()
                .as_ref()
                .map(|deadline| Duration::from_secs_f64(deadline.time_remaining() / 1000.0))
        })
    }

    fn now(&self) -> Instant {
        Instant::now()
    }
}

fn browser_window() -> web_sys::Window {
    web_sys::window().expect("must be running in a browser window context")
}

fn execute_on_main_thread(window: &web_sys::Window, item: MainThreadItem) {
    match item {
        MainThreadItem::Runnable(runnable) => {
            runnable.run();
        }
        MainThreadItem::Idle { runnable, timeout } => {
            schedule_idle_runnable(window, runnable, timeout);
        }
        MainThreadItem::Delayed { runnable, millis } => {
            let callback = Closure::once_into_js(move || {
                runnable.run();
            });
            window
                .set_timeout_with_callback_and_timeout_and_arguments_0(
                    callback.unchecked_ref(),
                    millis,

View on GitHub (pinned to f4178619ac)

Solutions

  1. Ensure dispatcher code is only used on the main thread/context where `window` is defined, not inside a Web Worker
  2. Cache the web_sys::Window reference once at platform startup so later calls cannot hit a missing global
  3. Return Option<Window> from the helper and propagate an error instead of panicking
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/gpui_web/src/dispatcher.rs:332 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of zed-industries/zed@f4178619ac (2026-08-20). Data as JSON: /api/errors/93dd9a2f8b7871ef. Report an issue: GitHub.