cargo-web
cargo-web copied to clipboard
How to polyfill (ie11 needs a random number generator).
Context: I'm trying to use web-view to render a yew frontend. Currently, on Windows, web-view uses ie11
to render.
Using
cargo web start --target=asmjs-unknown-emscripten
With a Web.toml
like this:
[target.emscripten]
link-args = ["-s", "LEGACY_VM_SUPPORT=1", "-s", "DEMANGLE_SUPPORT=1"]
ie11
produces the following error:
no cryptographic support found for random_device. consider polyfilling it if you want to use something insecure like Math.random(), e.g. put this in a --pre-js: var crypto = { getRandomValues: function(array) { for (var i = 0; i < array.length; i++) array[i] = (Math.random()*256)|0 } };
If you manually build and edit the demangled js
you can remove the error by applying the polyfill by hand.
Attempting to load the polyfill via prepend-js
in Web.toml
does not appear to work.
- Searching for any of the
prepend-js
code in the demangled output yields nothing. -
console.log
statements in theprepend-js
do not show up in theie11
console.
Perhaps there is a way to pass --pre-js
directly to emscripten?
It is not clear to me how to apply a polyfill, or how to test whether the polyfill was loaded outside of the two steps I mentioned.
The only other option I can think of is hack at the demangled output with custom code, replacing the one line in question. This would be last resort.
Thus ie11
is rendered unusable simply because of a security warning in emscripten.
PS I have had a good long look for help on this, please excuse me if I missed something obvious.