Trame + WASM: bind custom widget

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:
```cmake
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:
```
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

Can you show your <canvas> element?

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

1 Like

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 (5.8 KB)