Hi! I want to add wasmJs target to my app. But mak...
# webassembly
p
Hi! I want to add wasmJs target to my app. But make it such as client load binaries only if browser supports wasm gc, in other case load js version. Have somebody made such logic? Is it possible to detect if browser supports wasm gc from JavaScript?
r
I have this imperfect solution bookmarked: https://github.com/ragnorak-dev/ragnorakDev.github.io/blob/main/ragnorakWebsite.js thought it is not exactly what you want, it just checks for an Apple browser, so I'd like that wasm gc check as well
a
Also, you can take a look on the kotlinconf-app: https://github.com/JetBrains/kotlinconf-app/blob/master/shared/src/webMain/resources/index.html#L150 It's checking if there are all features that Kotlin/Wasm uses in a browser and in case of missing one of them it fallbacks to Kotlin/JS
p
Nice! Exactly what i need. Thanks!
Hello, @Artem Kobzar! I've applied your example and it works! Thanks! But I'm also looking for some optimizations. For example, what if provide only one wasm module to validate all three features at one time?
a
It's a nice suggestion, let me make such a module during this week
p
Nice! Please share it here when done.
👌 1
a
Copy code
const hasKotlinWasmSupport = () => 
    WebAssembly.validate(new Uint8Array([
        0,  97, 115, 109,   1,   0,   0,  0,   1,   8,   2,  95,
        1, 120,   0,  96,   0,   0,   3,  3,   2,   1,   1,  10,
       14,   2,   6,   0,   6,  64,  25, 11,  11,   5,   0, 208,
      112,  26,  11,   0,  45,   4, 110, 97, 109, 101,   1,  15,
        2,   0,   5, 102, 117, 110,  99, 48,   1,   5, 102, 117,
      110,  99,  49,   4,   8,   1,   0,  5, 116, 121, 112, 101,
       48,  10,  11,   1,   0,   1,   0,  6, 102, 105, 101, 108,
      100,  48
    ]))
Sorry for the late reply
It checks if the next Wasm is valid for a browser:
Copy code
(module
  (type $type0 (struct (field $field0 i8)))
  (func $func0
    try
    catch_all
    end
  )
  (func $func1
    ref.null func
    drop
  )
)
P.S. @PHondogo, I've just added the same check to the kotlinconf-app: https://github.com/JetBrains/kotlinconf-app/pull/144/files
p
Hello, Artem! Thank you!