Canvas host: fix action bridge invocation
This commit is contained in:
@@ -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 {}
|
||||||
|
|||||||
Reference in New Issue
Block a user