{"record":{"id":"69b60c9ab30b2037","repo":"zed-industries/zed","slug":"setting-canvas-readback-option-error","errorCode":null,"errorMessage":"setting Canvas readback option: {error:?}","messagePattern":"setting Canvas readback option: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/gpui_web/src/canvas_text.rs","lineNumber":39,"sourceCode":"}\n\nstruct TextCanvas {\n    canvas: OffscreenCanvas,\n    context: OffscreenCanvasRenderingContext2d,\n}\n\nimpl TextCanvas {\n    fn new() -> Result<Self> {\n        let canvas = OffscreenCanvas::new(1, 1)\n            .map_err(|error| anyhow!(\"creating text OffscreenCanvas: {error:?}\"))?;\n        let options = js_sys::Object::new();\n        // Every rasterized glyph is read back for upload into GPUI's atlas.\n        let assigned = js_sys::Reflect::set(\n            &options,\n            &JsValue::from_str(\"willReadFrequently\"),\n            &JsValue::TRUE,\n        )\n        .map_err(|error| anyhow!(\"setting Canvas readback option: {error:?}\"))?;\n        ensure!(assigned, \"Canvas readback option could not be set\");\n        let context = canvas\n            .get_context_with_context_options(\"2d\", &options)\n            .map_err(|error| anyhow!(\"getting OffscreenCanvas 2D context: {error:?}\"))?\n            .context(\"OffscreenCanvas 2D text rendering is unavailable\")?\n            .dyn_into::<OffscreenCanvasRenderingContext2d>()\n            .map_err(|error| anyhow!(\"unexpected OffscreenCanvas 2D context: {error:?}\"))?;\n        Ok(Self { canvas, context })\n    }\n\n    fn configure(&self, css_font: &str) -> Result<()> {\n        ensure!(!css_font.trim().is_empty(), \"Canvas text font is empty\");\n        // An invalid CSS font assignment is ignored by Canvas. Reset first so\n        // it cannot accidentally inherit the preceding request's font.\n        self.context.set_font(\"10px sans-serif\");\n        self.context.set_font(css_font);\n        self.context.set_text_align(\"left\");\n        self.context.set_text_baseline(\"alphabetic\");","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/zed-industries/zed/blob/916fc2b8cb3a815cbef4a3b40e13081be72036b6/crates/gpui_web/src/canvas_text.rs#L21-L57","documentation":"TextCanvas::new sets the willReadFrequently option on the context-options object via js_sys::Reflect::set. If the JS call throws or returns false, this error (or the following ensure!) is raised. It means the canvas context options object could not be configured, so glyph readback would be inefficient or misconfigured.","triggerScenarios":"Reflect::set on the freshly created object throws (rare, e.g. cross-realm or frozen object) or returns Ok(false) (property non-writable), which trips `ensure!(assigned, ...)`. Note this message only covers the map_err branch; a false return produces the 'could not be set' error.","commonSituations":"Exotic embedded JS runtimes or CSP/realm issues where web_sys object manipulation misbehaves; a bug in option-object construction upstream.","solutions":["Inspect the {error:?} payload for the underlying JS exception; it is usually an environment/runtime bug, not app input.","Update wasm-bindgen/web-sys versions to match, as cross-realm Reflect issues are often version-skew bugs.","As a last resort, drop willReadFrequently (it is a performance hint) and construct the context without it."],"exampleFix":"// before\nReflect::set(&options, &\"willReadFrequently\".into(), &JsValue::TRUE)\n    .map_err(|error| anyhow!(\"setting Canvas readback option: {error:?}\"))?;\n// after\nlet assigned = Reflect::set(&options, &\"willReadFrequently\".into(), &JsValue::TRUE)\n    .map_err(|error| anyhow!(\"setting Canvas readback option: {error:?}\"))?;\nif !assigned {\n    log::warn!(\"willReadFrequently not set; continuing without readback hint\");\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Treat the readback hint as optional; never fail text rendering because of it.\nif let Err(error) = set_readback_hint(&mut options) {\n    web_sys::console::warn_1(&format!(\"readback hint not set: {error:?}\").into());\n}","preventionTips":["Keep wasm-bindgen and web-sys versions in lockstep.","Treat willReadFrequently as a performance hint, not a correctness requirement.","Test web builds in non-standard embedded runtimes (Electron, WebView) where Reflect behavior can differ."],"tags":["web","wasm","javascript","canvas"],"backgroundTag":"invalid-config-value","analyzedSha":"916fc2b8cb3a815cbef4a3b40e13081be72036b6","analyzedAt":"2026-09-19T19:09:50.599Z","contentChangedAt":"2026-09-19T19:09:50.599Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}