Startup event

The initializer code snippet of Trunk will emit an event when the WebAssembly application has been loaded and started.


This event is independent of the initializer functionality.


The event is called TrunkApplicationStarted and is executed after the WebAssembly has been loaded and initialized.

The event will have custom details:

  wasm // The web assembly instance


The following snippet can be used to run code after the initialization of the WebAssembly application:

<script type="module">
  addEventListener("TrunkApplicationStarted", (event) => {
  console.log("application started - bindings:", window.wasmBindings, "WASM:", event.detail.wasm);
  // wasm_ffi is a function exported from WASM to JavaScript
  // You can also run this via the WASM instance in the details
  // event.detail.wasm.wasm_ffi();

Also see the vanilla example: