Last I checked, no WASM has direct DOM access, but instead it all has to go through a bridge to JS.
I assume if it’s even possible, it might execute the code only if the main thread is not executing any events - which happens only once per eventloop iteration.
I guess what is happening is that worker can call into JS, but can not access the DOM or anything else living on the main thread. They have to send messages to the other thread, just as JavaScript workers would need to do.
You can (and should) use Web Workers[1], those run off the UI thread, but also don't have access to the DOM.
[1] https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers...