{"record":{"id":"7a571ea98b503861","repo":"GraphiteEditor/Graphite","slug":"function-not-found","errorCode":null,"errorMessage":"Function not found","messagePattern":"Function not found","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"frontend/wrapper/src/native_communication.rs","lineNumber":79,"sourceCode":"\tserde_json::to_vec(&messages).ok()\n}\n\n#[cfg(all(feature = \"editor\", any(feature = \"native\", not(target_family = \"wasm\"))))]\npub fn decode_editor_command(data: &[u8]) -> Option<editor::messages::prelude::Message> {\n\tmatch serde_json::from_slice::<crate::EditorCommand>(data) {\n\t\tOk(command) => Some(command.into()),\n\t\tErr(e) => {\n\t\t\tlog::error!(\"Failed to deserialize editor command: {e}\");\n\t\t\tNone\n\t\t}\n\t}\n}\n\npub fn initialize_native_communication() {\n\tlet global = js_sys::global();\n\n\t// Get the function by name\n\tlet func = js_sys::Reflect::get(&global, &JsValue::from_str(\"initializeNativeCommunication\")).expect(\"Function not found\");\n\tlet func = func.dyn_into::<js_sys::Function>().expect(\"Not a function\");\n\n\t// Call it\n\tfunc.call0(&JsValue::NULL).expect(\"Function call failed\");\n}\n\npub fn send_message_to_cef(message: String) {\n\tlet global = js_sys::global();\n\n\t// Get the function by name\n\tlet func = js_sys::Reflect::get(&global, &JsValue::from_str(\"sendNativeMessage\")).expect(\"Function not found\");\n\n\tlet func = func.dyn_into::<js_sys::Function>().expect(\"Not a function\");\n\tlet array = Uint8Array::from(message.as_bytes());\n\tlet buffer = array.buffer();\n\n\t// Call it with argument\n\tfunc.call1(&JsValue::NULL, &JsValue::from(buffer)).expect(\"Function call failed\");","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/GraphiteEditor/Graphite/blob/c507b356453361e31638b8bff8f6d46b6da2961e/frontend/wrapper/src/native_communication.rs#L61-L97","documentation":"initialize_native_communication resolves window.initializeNativeCommunication on the JS global through js_sys::Reflect::get and panics when retrieval fails. That function is injected by the native CEF shell hosting the editor; outside that host — or before the bridge script has run — the global does not exist.","triggerScenarios":"Loading the native-communication build in a plain browser; the host page script that defines the bridge not yet executed when the wasm start function runs; the native host renaming or omitting the injected global for this build.","commonSituations":"Testing a CEF-targeted build in a normal browser; script load order so the wasm instantiates first; version drift between the wrapper's expected global names and the native shell's injected API.","solutions":["Load the JS bridge that defines initializeNativeCommunication before the wasm module instantiates","Gate this init path to the CEF host (feature flag or runtime check) and no-op elsewhere","Replace the expects with Reflect::get plus dyn_ref::<Function>() checks that log a warning when the bridge is absent"],"exampleFix":"// before\nlet func = js_sys::Reflect::get(&global, &JsValue::from_str(\"initializeNativeCommunication\")).expect(\"Function not found\");\n\n// after\nlet Ok(found) = js_sys::Reflect::get(&global, &JsValue::from_str(\"initializeNativeCommunication\")) else {\n\terror!(\"native bridge not present; skipping CEF initialization\");\n\treturn;\n};\nlet Ok(func) = found.dyn_into::<js_sys::Function>() else {\n\terror!(\"initializeNativeCommunication is not callable\");\n\treturn;\n};","handlingStrategy":"type-guard","validationCode":"// host page, before loading the wasm bundle:\n// typeof window.initializeNativeCommunication === 'function'","typeGuard":"fn global_function(name: &str) -> Option<js_sys::Function> {\n\tjs_sys::Reflect::get(&js_sys::global(), &JsValue::from_str(name))\n\t\t.ok()?\n\t\t.dyn_ref::<js_sys::Function>()\n\t\t.cloned()\n}","tryCatchPattern":null,"preventionTips":["Define bridge globals in a synchronous script tag placed before the wasm bundle","Feature-gate native communication so browser builds never call it","Log the typeof of each expected bridge global during startup diagnostics"],"tags":["cef","js-interop","wasm-bindgen","globalthis"],"backgroundTag":"missing-global-js-function","analyzedSha":"c507b356453361e31638b8bff8f6d46b6da2961e","analyzedAt":"2026-08-16T21:57:18.596Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}