UXP, InDesign: WebView postMessage does not work in 20.4
Since version 20.4 of InDesign, sending messages to the WebView element no longer works. Here is a dummy plugin to reproduce the behavior.
https://kdrive.infomaniak.com/app/share/1606376/dbdbc8c1-10c3-4c9a-b4ce-d048fc2864fd
How to test?
Click on the “Send message” button.
Expected behavior?
The message “Hello form panel!” appears in the Webview element (white background).
In InDesign 20.3 it works, from 20.4 no longer.
Why is this important?
This affects the functionality of one of my published plugins.
Code:
Plugin:
const sendMessageButtonElem = document.getElementById("send-message-button");
sendMessageButtonElem?.addEventListener("click", () => {
/* Send message to WebView */
const webviewElem = document.getElementById("webview") ;
webviewElem.postMessage({
"message": "Hello from panel!"
});
});
Webview:
/**
* Window message event listener
* Receive messages from Plugin
*/
window.addEventListener("message", panelMessageHandler);
/**
* Panel message handler
* @param evt
* @returns
*/
async function panelMessageHandler(evt: MessageEvent) {
const webviewMessageOutputElem = document.getElementById("webview-message-output") as HTMLElement;
webviewMessageOutputElem.textContent = evt.data.message;
}
