Janestreet/bonsai: calling inject from window.onMessage handler

I have the following problem:

index.html is running a bonsai app
other iframes talks to index.html via postMessage

when index.html receives a msg via onMessage, within the onMessage handler, I want to call inject / do something to change some Value.t

I thought bonsai/examples/rpc_chat/client/src at master · janestreet/bonsai · GitHub would be relevant, but I don’t see how it is linking “onmessage” with bonsai.

Question: Is there any sample code of how to get a onmessage handler to call niject / modify a Value.t ?


I figured this out. A similar problem occurs in the drag_and_drop example, where a ‘pointermove’ event handler is registered on the global window.

The solution is to use:

             (match Bonsai_web.am_within_disabled_fieldset event with
              | true -> inject [ Set_target None; Mouse_moved position ]
              | false -> inject [ Set_target target; Mouse_moved position ]);