15

GraalVM has so many surprising capabilities. But one thing I haven't seen, but would like to, is to be able to run a GraalVM application in a browser. Sources like this (Top 10 Things To Do With GraalVM) shows interop with Node.js, but not running a compiled application in the browser.

Is this possible? If so, is there documentation on this? Thanks!

Erik Kaplun
  • 37,128
  • 15
  • 99
  • 111
Jeff
  • 939
  • 10
  • 19
  • I imagine you would need to recompile the browser to use a different JavaScript engine than its usual one. And that swapping out the JavaScript engine would be a substantial amount of work. But you could ask about it on the [graalvm/graal-core Gitter channel](https://gitter.im/graalvm/graal-core). – ctrueden Jul 02 '18 at 20:14
  • While the possibilities are tempting I could imagine that including graalvm into a browser has security implications. I think code executed by browsers is untrusted. Hence it must be restricted in something like a sandbox to avoid that it does malicious side effects. Multiple sandbox technologies have been victim of malicious code breaking out. E.g. the Java browser plugin. That's why it is basically gone. GraalVM seems even more complex and hence harder to secure to me. – user573215 May 02 '19 at 18:44
  • Not yet, but you can track https://github.com/oracle/graal/issues/3391 – Christian Beikov Sep 21 '21 at 10:22

2 Answers2

4

Well, it looks like this may be possible using Webassembly. From the Graal VM lead Thomas Wuerthinger: https://twitter.com/thomaswue/status/943592646915878912?lang=en

Webassembly is useful for statically typed languages (as LLVM backend). I am not aware of any Ruby, R, or Python implementation successfully targeting Webassembly. Graal VM will be able to run via Webassembly in the browser. It also has a "native" mode with standalone binaries.

So if you're coding in something like Clojure or Python and planning on compiling to Webassembly via Graal VM, you would likely run up against the same restrictions that Webassembly has, such as the browser sandbox and only being able to access web APIs. It will be interesting to see if those boundaries can be communicated through error messages or other compile-time checks.

Jeff
  • 939
  • 10
  • 19
  • 7
    It's been 3 years since this announcement: is it yet possible to run Graal VM in WebAssembly? – Anderson Green Sep 28 '21 at 13:23
  • @AndersonGreen There's an issue about that: https://github.com/oracle/graal/issues/3391 The garbage collection proposal is going forward, it should be very helpful to drive such things possible but it's still not a trivial task. – gouessej Aug 30 '23 at 07:15
2

It would be very interesting to see a browser that embeds GraalVM and can run its engine for languages, even if only for JavaScript initially.

Currently, there's no such browsers, as far as I know. Maybe an interesting first step would be to take Electronjs, and try replacing the version of node they use with the version of node.js from GraalVM. It's not trivial, since they introduce some changes to the stock node.js and GraalVM introduces some changes when replaces the JavaScript engine with its own implementation.

However, it definitely should be possible to achieve.

Oleg Šelajev
  • 3,530
  • 1
  • 17
  • 25