Element type in the iframe is not the same as the
Element type in the parent frame. This bizarrely means, for example, that “
iframe.contentDocument.body instanceof Element” returns false!
The same thing is happening here. The Workers runtime compiles the WebAsssembly module in a different context from the one that actually executes requests. The reason for this has to do with Cloudflare Apps: When the same app is installed on multiple web sites, we only want to compile the app (and any WebAssembly modules) once. But, we want to make sure the app can’t accidentally leak data between web sites. So, we run each web site in a different context, within the same V8 isolate.
Unfortunately, this means that we cannot make our WebAssembly modules be
instanceof WebAssembly.Module, because we’d have to decide which context’s module it should be an instance of, and then it wouldn’t work in any of the other contexts.
Instead, to fix the problem, we need to fix wasm-bindgen to be more compatible with Workers.
The good news is there’s going to be a lot more movement on this soon, because: