Canvas host: fix action bridge invocation

This commit is contained in:
Peter Steinberger
2025-12-19 00:04:26 +01:00
parent 47510e2912
commit 256080e2a2

View File

@@ -38,14 +38,15 @@ export function injectCanvasLiveReload(html: string): string {
function postToNode(payload) { function postToNode(payload) {
try { try {
const raw = typeof payload === "string" ? payload : JSON.stringify(payload); const raw = typeof payload === "string" ? payload : JSON.stringify(payload);
const ios = globalThis.webkit?.messageHandlers?.[actionHandlerName]?.postMessage; const iosHandler = globalThis.webkit?.messageHandlers?.[actionHandlerName];
if (typeof ios === "function") { if (iosHandler && typeof iosHandler.postMessage === "function") {
ios(raw); iosHandler.postMessage(raw);
return true; return true;
} }
const android = globalThis[actionHandlerName]?.postMessage; const androidHandler = globalThis[actionHandlerName];
if (typeof android === "function") { if (androidHandler && typeof androidHandler.postMessage === "function") {
android(raw); // Important: call as a method on the interface object (binding matters on Android WebView).
androidHandler.postMessage(raw);
return true; return true;
} }
} catch {} } catch {}