# Trame + WASM: bind custom widget

**URL:** https://discourse.vtk.org/t/trame-wasm-bind-custom-widget/16350
**Category:** Web
**Tags:** trame, vtkwasm, python
**Created:** [March 22, 2026, 8:49pm UTC](https://discourse.vtk.org/t/trame-wasm-bind-custom-widget/16350 "2026-03-22T20:49:21Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![kerim](https://discourse.vtk.org/user_avatar/discourse.vtk.org/kerim/32/1175_2.png) [@kerim](https://discourse.vtk.org/u/kerim)
#### Post date: [March 22, 2026, 8:49pm UTC](https://discourse.vtk.org/t/trame-wasm-bind-custom-widget/16350/1 "2026-03-22T20:49:21Z")

</div>

Hi,

I wrote custom widget in C++ fork of VTK 9.6 and now I’m trying to port it to Trame local view using WASM approach.

My approach is to build VTK WASM, install trame-vtklocal package with VTK\_WASM\_DIR\_OVERRIDE env var set to wasm dir and rutn the trame app. When launching Trame app I get an error:

`JS Error => WASM update failed`  
`JS Error => 2026-03-22 23:44:25.998 ( 0.181s) [7E3834]vtkWebAssemblyOpenGLRen:221 ERR| vtkWebAssemblyOpenGLRenderWindow (0x86b098): Error (0) initializing WebGL2.`  
`JS Error => 2026-03-22 23:44:25.999 ( 0.182s) [7E3834]vtkWebAssemblyOpenGLRen:245 ERR| vtkWebAssemblyOpenGLRenderWindow (0x86b098): Failed to create Emscripten opengl context`  
`JS Error => TypeError: Cannot read properties of undefined (reading ‘getParameter’)`

and the app doesn’t work even though it works when running remote view.

What am I missing?

To configure wasm I use this command:

```auto
emcmake cmake `

-S $env:VTK_SOURCE_DIR `

-B $env:VTK_BUILD_DIR `

-G “Ninja” `

-DCMAKE_BUILD_TYPE=Release `

-DBUILD_SHARED_LIBS=OFF `

-DVTK_GROUP_ENABLE_Web=WANT `

-DVTK_WRAP_SERIALIZATION=ON `

-DVTK_WEBASSEMBLY_THREADS=ON `

-DVTK_WRAP_JAVASCRIPT=OFF `

-DVTK_ENABLE_WEBGPU=ON

```

and I intensionally disable javascript wrapping ( -DVTK\_WRAP\_JAVASCRIPT=OFF) because otherwise it produce the error:

```auto
CMake Error at CMake/vtkModuleWrapJavaScript.cmake:468 (target_link_libraries):
Target “VTK::WebAssemblyAsync” of type EXECUTABLE may not be linked into
another target. One may link only to INTERFACE, OBJECT, STATIC or SHARED
libraries, or to executables with the ENABLE_EXPORTS property set.
Call Stack (most recent call first):
CMakeLists.txt:797 (vtk_module_wrap_javascript)

CMake Error at CMake/vtkModuleWrapJavaScript.cmake:468 (target_link_libraries):
Target “VTK::WebAssembly” of type EXECUTABLE may not be linked into another
target. One may link only to INTERFACE, OBJECT, STATIC or SHARED
libraries, or to executables with the ENABLE_EXPORTS property set.
Call Stack (most recent call first):
CMakeLists.txt:797 (vtk_module_wrap_javascript)

– Configuring incomplete, errors occurred!

```

Appreciate any help

---

<div class="post-metadata">

### Author: ![jaswantp](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jaswantp/32/10046_2.png) [@jaswantp](https://discourse.vtk.org/u/jaswantp)
#### Post date: [March 22, 2026, 10:03pm UTC](https://discourse.vtk.org/t/trame-wasm-bind-custom-widget/16350/2 "2026-03-22T22:03:55Z")

</div>

Can you show your `<canvas>` element?

`Error (0) initializing WebGL2` shows up when VTK does not know about your canvas.

---

<div class="post-metadata">

### Author: ![kerim](https://discourse.vtk.org/user_avatar/discourse.vtk.org/kerim/32/1175_2.png) [@kerim](https://discourse.vtk.org/u/kerim)
#### Post date: [March 22, 2026, 10:49pm UTC](https://discourse.vtk.org/t/trame-wasm-bind-custom-widget/16350/3 "2026-03-22T22:49:30Z")

</div>

Thank you for response.

The `canvas` you mean how it looks like?  
I attach the photo and the Trame code (in the file because I got bad formatting on the forum somehow)

[custom\_widget\_trame.py](https://discourse.vtk.org/uploads/short-url/jZacs6QIT8kjShnMe26VLxwtrxr.py) (5.8 KB)

 ![image](https://discourse.vtk.org/uploads/default/original/2X/8/8b6dfd5f29d6fac8c07ba2c4bf7f9e33638dc671.png)

---

<div class="post-metadata">

### Author: ![kerim](https://discourse.vtk.org/user_avatar/discourse.vtk.org/kerim/32/1175_2.png) [@kerim](https://discourse.vtk.org/u/kerim)
#### Post date: [March 23, 2026, 9:37am UTC](https://discourse.vtk.org/t/trame-wasm-bind-custom-widget/16350/4 "2026-03-23T09:37:42Z")

</div>

By the way there is no problem to run [clip\_rendering.py](https://github.com/Kitware/vtk-wasm/blob/main/examples/trame/widget/clip_rendering.py "clip\_rendering.py") example from [vtk-wasm](https://github.com/Kitware/vtk-wasm) repo:

 ![image](https://discourse.vtk.org/uploads/default/original/2X/9/9945f8d77a49c3d6ea1e1cf66f3fde7e9fe3a282.png)
