zed-industries/zed · error

No `body` found on document

Error message

No `body` found on document

What it means

Guard in WebWindow::prepare_canvas: document.body() returned None — the document has no <body> element yet (script ran in <head> before body parsing) or the document type never has a body (e.g. XML documents).

Solutions

  1. Run initialization after DOMContentLoaded so document.body exists
  2. Use document.documentElement as an append target when body is absent
  3. Defer canvas insertion with a MutationObserver if the host page builds body dynamically
Defensive patterns

Strategy: validation

When it happens

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

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at crates/gpui_web/src/window.rs:109

}

pub struct WebWindow {
    inner: Rc<WebWindowInner>,
    display: Rc<dyn PlatformDisplay>,
    lifecycle: Rc<Cell<WebWindowLifecycle>>,
    active_window: Rc<RefCell<Option<AnyWindowHandle>>>,
    _raf_closure: Closure<dyn FnMut()>,
    _resize_observer: Option<web_sys::ResizeObserver>,
    _resize_observer_closure: Closure<dyn FnMut(js_sys::Array)>,
    _safe_area_observer: Option<web_sys::ResizeObserver>,
    _safe_area_observer_closure: Closure<dyn FnMut(js_sys::Array)>,
    _event_listeners: WebEventListeners,
}

impl WebWindow {
    pub(crate) fn prepare_canvas(
        browser_window: &web_sys::Window,
    ) -> anyhow::Result<web_sys::HtmlCanvasElement> {
        let document = browser_window
            .document()
            .ok_or_else(|| anyhow::anyhow!("No `document` found on window"))?;
        let canvas: web_sys::HtmlCanvasElement = document
            .create_element("canvas")
            .map_err(|error| anyhow::anyhow!("Failed to create canvas element: {error:?}"))?
            .dyn_into()
            .map_err(|error| anyhow::anyhow!("Created element is not a canvas: {error:?}"))?;
        canvas.set_tab_index(-1);

        let style = canvas.style();
        for (property, value) in [
            ("width", "100%"),
            ("height", "100%"),
            ("display", "block"),
            ("outline", "none"),
            ("touch-action", "none"),
            ("-webkit-touch-callout", "none"),

View on GitHub (pinned to 9d272b0363)