Homepage    |    GitHub    |    API    |    FAQ

postMessage from the plugin to a webview panel

Hi!

First of all, props to everyone involved in development of Joplin. It's a pleasure to use, and has become an indispensable tool in my daily life. I recently started working on my first Joplin plugin, and the new plugin API is a pleasure to work with. Great work, thank you!

I'm relatively new to the Joplin codebase, so apologies if I'm missing something obvious, but – is there a way to send data via postMessage from a plugin to a webview panel instead of only responding to a message?

My plugin has a command that can be invoked from multiple places. It extracts information from the current note (or multiple notes, or a whole notebook, depending on where it's invoked from), displays the data in a panel for user confirmation and editing, and then sends it off to an external API.

The UI in the webview is built with preact. I would like to keep all data processing in the plugin thread and just send the new data to the webview without re-rendering the whole panel via panels.setHtml on every execution.

Thank you!

I guess you can try something like this:

  • when your webview loads, send a message to the plugin
  • in the plugin return a promise, but do not resolve it, instead store a reference to the promise
  • when it's time to send data back to webview, retrieve the promise and resolve it with the data
  • repeat
1 Like

Feels like a bit of a hack, but it will have to do :slight_smile:
Are there security related reasons why it's not possible in a more tidy way?
Either way, I'll try it out and see how that works, thank you!