zed-industries/zed · error
Failed to append canvas to body: {error:?}
Error message
Failed to append canvas to body: {error:?} What it means
Guard in WebWindow::prepare_canvas: body.appendChild(canvas) threw — {error:?} is the JS exception, typically a HierarchyRequestError (body is not attached, e.g. detached document) or a CSP violation blocking DOM insertion.
Source
Thrown at crates/gpui_web/src/window.rs:111
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"),
("user-select", "none"),
("-webkit-user-select", "none"),View on GitHub (pinned to 9d272b0363)
Solutions
- Ensure the body is connected to the document before appending the canvas
- Check page CSP for restrictions on DOM modification
- Report the JS exception so the embedding-page issue is visible in diagnostics
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at crates/gpui_web/src/window.rs:107 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/adba92a3f9111710.
Report an issue: GitHub.