Working on a document traversing plugin, I was required to build up a progress indicator in the UI. Basically traversing
- all pages
- all componentSets
- all components
in this order.
I had communication working between code and ui, but from one day to another, this changed. Now I can get only message from UI to code, but not back. Code is sending, no matter what I am handing it for sending, “undefined” ..
On UI side, this is awaiting the messages:
window.addEventListener("message", (event) => {
console.log("Received " + event.data.postMessage)
if (event === undefined) {
console.error("undefined event sent, why?")
return;
}
if (event.data === undefined) {
console.error("undefined event.data sent, why?")
return;
}
if (event.data.postMessage === undefined) {
console.error("undefined event.data.postMessage sent, why?")
// ^ it breaks here, since postMessage is undefined
return;
}
// .. actual code comes here, but not required, fails above already
});
On Code (backend) side I send it during a async execution ..
async function GoAndGetThemTiger () {
cancelExecution = false;
let pageCurrentNumber = 0;
for (const page of figma.root.children) {
figma.ui.postMessage("TEST!!!!!"); // usually this worked
await page.loadAsync();
}
}
figma.showUI(__html__);
figma.ui.resize(500, 800);
// .. does not work
figma.ui.postMessage("Yes, let's kick of creation!");
// .. doesn't work neither
GoAndGetThemTiger();
What am I doing wrong here?
Any hints and remarks are welcome and happy to receive (unlike this message receiver :D )
Many thanks,
M