Messaging between loaded Office JS addins?

T.J. Crowder 1 Reputation point

We have two separate Office JS addins for Excel (served from the same origin). Is there any way to do messaging between them? Something like postMessage but we don't really care about the mechanism as long as there is one. We need it to work in Excel Desktop and also Excel for the Web.

Here's one use case: A custom functions addin (we have five of them) that can report custom function errors by sending a message to a task pane addin that displays them. We don't want each of the custom functions addins to have their own task pane, hence the messaging.

I've taken a stab at doing it fairly crudely via localStorage and via, but I've found some really funky things in Excel Desktop. For instance, at one point addin A (task pane) wasn't seeing the things added by addin B (custom function) and I eventually found that addins A and B were running in different versions of Edge. (v99 and v100 respectively, IIRC). This was soon after Excel had updated. When it was happening, Edge itself was still saying it was v99. When that was happening, it happened both with localStorage and with (which looked like it was just using localStorage anyway, but hopefully behind the scenes there was more going on.) Seeing two different versions of the web control like that was ... troubling. But now I can't replicate it, they both say they're Edge v100 and they see the storage just fine. :-|

Some official messaging would be preferable.


-- T.J.

JavaScript API
JavaScript API
An Office service that supports add-ins to interact with objects in Office client applications.
912 questions
Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,653 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. T.J. Crowder 1 Reputation point

    In up-to-date versions of Excel, you can use BroadcastChannel (MDN) to send messages reliably between add-ins. (You may need to updated the add-ins to use the shared runtime, I'm not sure; but Microsoft recommends that anyway.) You need up-to-date Excel so your add-ins run in the Edge-based WebView2 (not the IE-based WebView, which didn't support BroadcastChannel).

    0 comments No comments