Blazor

How can I check if a browser supports WebAssembly?

How can I check if a browser supports WebAssembly?

You can check whether a type of WebAssembly is an object in global scope, but the global scope is not a feasible one across different JavaScript environments, such as the main browser thread, worker, Node.js.

The more feasible solution is as follows.

 const supported = (() => {
      try {
 if (typeof WebAssembly === "object"
             && typeof WebAssembly.instantiate === "function") {
             const module = new WebAssembly.Module(Uint8Array.of(0x0, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00));
             if (module instanceof WebAssembly.Module)
                 return new WebAssembly.Instance(module) instanceof WebAssembly.Instance;
         }
     } catch (e) {
     }
     return false;
 })();
  
 console.log(supported ? "WebAssembly is supported" : "WebAssembly is not supported");   

I would suggest you check the below link for better understanding:

https://stackoverflow.com/questions/47879864/how-can-i-check-if-a-browser-supports-webassembly

Sumitra Kumari Shaw

An Engineering graduate who Enjoys building things that live on the internet.