zed-industries/zed · error

Failed to create canvas element: {error:?}

Error message

Failed to create canvas element: {error:?}

What it means

Guard in WebWindow::prepare_canvas: document.createElement('canvas') threw — {error:?} is the JS exception. Usually a Document with an inert/locked DOM, custom-element interference, or a stripped-down embedding context that rejects element creation.

Source

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

    pub(crate) is_composing: Cell<bool>,
    /// Set while `show_virtual_keyboard` blur/focus-cycles the hidden input.
    /// The cycle is a keyboard-visibility hint, not a real activity change;
    /// letting the focus/blur listeners report it would re-enter GPUI
    /// synchronously from inside an input dispatch, and a `RefCell`
    /// double-borrow panic on wasm never unwinds, wedging the app.
    pub(crate) suppress_focus_status_events: Cell<bool>,
    /// The visual viewport height when the current pointer gesture began.
    /// A mid-gesture change means the software keyboard opened or closed and
    /// reflowed the layout, so the release position no longer refers to what
    /// the user aimed at.
    pub(crate) gesture_start_visual_viewport_height: Cell<f64>,
    /// A touch that may still resolve into a tap: its pointer id and starting
    /// position, cleared once it travels beyond touch slop. Virtual keyboard
    /// and IME focus may only change when a touch release completes a tap;
    /// pans must leave them untouched, or scrolling over editable content
    /// flickers the keyboard and drags the caret around.
    pub(crate) touch_tap_candidate: Cell<Option<(i32, Point<Pixels>)>>,
    mql_handle: RefCell<Option<MqlHandle>>,
    pending_physical_size: Cell<Option<(u32, u32)>>,
    raf_id: Cell<Option<i32>>,
    raf_function: RefCell<Option<js_sys::Function>>,
}

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,
}

View on GitHub (pinned to 9d272b0363)

Solutions

  1. Verify the page is a normal HTML document (not XML/inert) before creating the canvas
  2. Check for CSP or sanitizer environments that block dynamic DOM insertion
  3. Propagate the JS error detail so the embedding context problem is diagnosable
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at crates/gpui_web/src/window.rs:85 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/fc52556fc1cdba8a. Report an issue: GitHub.