5 ms·
Show HN: Does your browser supports WebAssembly?
- TACIXAT 6y agoCould you save some of this data and show a table of what has been checked? Guess I could just check caniuse.
- tta 6y agohttps://developer.mozilla.org/en-US/docs/WebAssembly#Browser_compatibility https://developer.mozilla.org/en-US/docs/WebAssembly#Browser...
- deleted 6y ago[deleted]
- ggreer 6y agoIt just seems to display a blank blue page on browsers that don’t support WebAssembly. I tested on Safari 9 and the Nintendo 3DS browser.
- _Microft 6y agoI'm not up-to-date regarding JS programming, so: why is this solved as it is, i.e. as anonymous function that is immediately called? First idea would be to prevent leaking anything into a global context but this shouldn't be an issue here. Can anyone explain? var 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; })(); Edit: is it maybe to save one from having to think about leaking anything, i.e. wrap everything in (() => { ... })(); and call it a day?
- Vanit 6y agoI think this is an attempt to keep the code clean without multiple assignments to 'supported'. I don't think there's any real benefit. Unless something else took a reference to it the GC will get it after the main script has run.
- joway 6y agoHi, actually, the function is referenced from https://stackoverflow.com/questions/47879864/how-can-i-check-if-a-browser-supports-webassembly https://stackoverflow.com/questions/47879864/how-can-i-check... . :( But I think there are two reasons to write like that: 1. It avoids multiple assignments, which could make codes cleaner. 2. My website is too simple so maybe there is no enough reason to do such "optimization". But if we are talking about a big project, this initialized global variable could make other codes which required to check if the wasm feature enabled easier and just need to calculate the status one time.
- maxgraey 6y agoif you want not only check supporting WebAssembly but also support by version, which post-MVP feature currently support in your browser like simd, threads, multi-values and etc check this package: btw it use only WebAssembly.validate which much faster and synchronous: https://www.npmjs.com/package/wasm-check https://www.npmjs.com/package/wasm-check