This Browser Supports Webassembly? At what degree?
How to make sure your Webassembly code can run on your user’s browser? Besides, as Webassembly evolves, your application is going to encounter a mixed population of browser versions with different degrees of Webassembly support. This is not true today, but will be in the near future, for instance, threads is a new feature that is coming to Webassembly. How to tell what Webassembly features are supported by your user’s browser?
And if my User’s Browser Does Not Support Webassembly at All?
Your user may not have a chance to use a newer browser, this situation can happen in a rigid corporate environment, where the approved browser version does not support Webassembly. Two choices:
1.Request the user to get a newer browser and then quit your application. This is the easiest developer implementation, but perhaps not the most helpful.
Your application may fail erratically If you run it on a browser that does not support all the Webassembly features used by it.
Then you can blame on the machine:
How to Test my Webassembly Application in a Browser That Does Not Support Webassembly?
You can disable Webassembly support in your browser and then check what is going to happen with your application. In Firefox, open about:config, then Accept the risk, but be careful because you could void Firefox warranty, really?
How to Tell if my Webassembly Application is going to run?
The Webassembly object only exists if the browser supports Webassembly, but there is a more complete check that, as shown later in this post, allows checking if a particular Webassembly feature is implemented in the browser. Look at this self contained HTML file:
The WasmSupported() function accomplishes the following important tasks before asserting the browser can run Webassembly code:
- The browser can create a Webassembly module.
- The browser can create a Webassembly instance.
- The browser can execute a Webassembly function.
What Is that Bunch of Bytes in Uint8Array?
All bits in that sequence is explained in Dissecting a Minumum Webassembly Module. Don’t miss that post as it shows how to write Webassembly in its text format!
Wait a Minute and How About Checking for Webassembly New Features?
There are lots of new features that are going to be added to Webassembly. Threads is a big one that I am going to use as an example. So lets assume your new Webassembly application uses threads (when eventually implemented). Your application is going to encounter browsers that supports Webassembly, but not threads, like our today’s browser. In that situation the code above will tell you the user’s browser supports Webassembly, but your code will fail when trying to use threads. What we should do then?
There are a couple of ways to check this browser limitation ahead of time and fail gracefully (does such a thing exists?) and tell your user the accurate problem, which would be your browser version does not support Webassembly threads. Or, instead of failing, run a version of your application that does not use threads.
The simplest way I can think of would be to change the Webassembly module above, which currently only has a XOR() function, to have another function, lets call it BrowserSupportsWasmThreads(). The BrowserSupportsWasmThreads() function would do some basic thread operations, maybe it would only create a thread and then delete it, and then return TRUE if all thread operations worked and FALSE otherwise. Then change the WasmSupported() function to call BrowserSupportsWasmThreads().
Your application should have as many functions as necessary to figure out what Webassembly features are not supported by your user’s Browser. And then take what you consider appropriated action, fail or workaround.
It is not very laborious to verify in detail what Webassembly features your user’s browser support and then take a more clear action. Or you could start memorizing the
Somebody must have changed my code.
I’ve never heard about that.
It did work yesterday.
How is this possible?
I can’t test everything!
THIS can’t do THAT.
Didn’t I fix it already?
There must be a virus in the application software.
According to my calculations the problem doesn’t exist.